There is no 302 Redirect.
The most common use case is that you have URLs which return user profiles such as
http://www.example.com/user/1
Friendly URLs allow you to create a URL so that the user can also be accessed by going to:
http://www.example.com/jeff
The key is that the address bar in the browser does not change to http://www.example.com/user/1
The web server returns the same HTML document as http://www.example.com/user/1
Flow
-----
The application looks up the string 'jeff' If it finds a friendly url match it will read out the absolute_path
and attempt to resolve it by putting it through the URL resolver a 2nd time.
If it finds a resolution it will return that view.
Usage
-----
Here is an example of how to implement friendly_urls for a user:
I put this in models.py:
from django.contrib.contenttypes import generic
from friendlyurls import UrlMapping
from django.contrib.auth.models import User
def get_absolute_url(self):
return u'/user/%s' % self.id
User.add_to_class('friendly_urls', generic.GenericRelation(UrlMapping))
User.get_absolute_url = get_absolute_url
This basically monkey patches the User model to add a field. You can then do
user = User.objects.get(pk=1)
user.friendly_urls.all()
This will get a list of all the friendly urls.
You shouldn't have to monkey patch all the models.
Problems / Questions
--------------------
Don't forget to run syncdb because friendlyurls creates a table to store the URL mappings.
Additional Settings
-------------------
FRIENDLYURLS_IGNORE_CASE - Set this to True if you want to ignore the case when trying to find a path. Default: False
Todo Features
-------------
- Need to cache the results returned by a lookup for performance.
Probably do a from django.core.cache import cache
https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs
Metadata
Release files for django_friendlyurls 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_friendlyurls-0.1.1.tar.gz | 4.7 kB | Without provenance | Details for django_friendlyurls-0.1.1.tar.gz |
Release files / django_friendlyurls-0.1.1.tar.gz
| Download URL | django_friendlyurls-0.1.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
387c506b7a0ec4aa16b9088158b4b513cda95f67438bd08112aadc98c04dfff8
|
|
BLAKE2b-256 checksum How to use checksums |
911369d85892b2a6c8f5a09a338b88b1da451a4fe949d8d664dba6956a5d2339
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django_friendlyurls 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.