-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
entry detail url format change #27
Comments
Thanks, I can see how a project would find that useful. I agree that it would be best as an optional feature. Do you have any recommendations of examples/tutorials/posts for doing something like this with a Django site? It may help whoever wants to take a stab at a pull request for this feature. |
Reading up on this approach a bit more I think we can implement it without having to make it optional. When I first came this I wasn't sure how a site like stackoverflow did this without violating canonicalization. I see now that they do a permanent redirect when someone navigates to the URL without the slug (just the Id) to the URL with both the Id and the slug (as opposed to loading the same page at a second URL). TL;DR: This can be implemented without having to make it optional if we make sure that the we have a view that redirects the /{id} URL form to the primary view at /{id}/{slug}. |
To address this issue we would need tests for both URL forms in test_entry_detail.py. |
One idea would be to set the url scheme through a couple of settings with defaults that keep the current behavior. Something like this (I've dabbled with this, but it's still a fairly rough idea):
The default URLConf would look something like this: url(settings.ANDABLOG_ENTRY_PATTERN, views.EntryDetail.as_view(), name='entrydetail'), And def get_absolute_url(self):
args = [getattr(self, field) for field in settings.ANDABLOG_ENTRY_ARGS]
return reverse('andablog:entrydetail', args=args) A user of the app might set the following: ANDABLOG_ENTRY_PATTERN = r'(?P<id>\d+)-(?P<slug>[A-Za-z0-9-_]+)/$'
ANDABLOG_ENTRY_ARGS = ('id', 'slug', ) And the URL for an entry would be: This is a fairly flexible approach that lets users set their own schemes but dosen't require building new views. New users could define URLs however they want, and if existing users wanted to change their scheme, they'd have to handle orphaned URLs themselves, which I think is OK. I'm happy to get any feedback on this idea 😄 |
I think that is an excellent idea. Though in keeping with the spirit of the project (easy integration) I think the feature would also need some pre-canned forms that people can use. They can be mentioned in the documentation. I think this is important so that those with alternate needs but not URL opinions can get going quickly. For instance, I see three cases mentioned in here already. 1. The defaultSlug lookup only. Advantage: URL simplicity 2. Id only lookup /{id}/{slug}This still uses a friendly URL but uses the Id for lookup. A URL with only the Id causes a 301 redirect to the id/slug form. Advantage: Performance (id based lookup) and support for entry renaming.
3. Id and slug lookup /{id}-{slug}This uses both an Id and slug for lookup. Advantage: Performance (id and slug based lookup)
CustomSet ANDABLOG_ENTRY_PATTERN to your own url pattern and ANDABLOG_ENTRY_ARGS to the fields that should be used for lookup. Caveats
|
Hmm... maybe instead of magic strings we could put the pre-canned things under different bool-type settings all together in keeping with the original optional idea. Either way, they would invoke the same code as ANDABLOG_ENTRY_PATTERN/ARGS behind the scenes. |
I suggest placing pk of entry into url format and lookup from entry with id not from slug ,
when people need to change title of entry they won't bother with 301 redirects or 404 errors later
this can be optional so people can use as they want
sample
from -> blog/this-is-entry-instance
to -> blog/1/this-is-entry-instance
The text was updated successfully, but these errors were encountered: