let say the user chooses the name "Elsa Frozen"
now his slug would be "Elsa-Frozen-5"
it means 4 other people have used the same header
now he can go to url: "your website.com/Elsa-Frozen-4" to see other people's Post
This module extends the standard `url' template tag in Django and adds support for fully qualified domain name URLs. It also can be extended with simple URL load balancing techniques if desired.
See my blog for the background story:
<http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/>
**Use case:**
Suppose you are working on maintenance screens on some data objects. On one particular page (a form) you want to have exits directly back to a calling page (as a cancel operation) or indirectly back to the calling page (after an data update operation). However, the form and its object are not directly related to the target page (perhaps a one-to-many relationship) so you cannot figure the calling page from object data - but the target object IS referenced in the url.
** How To:**
To make this work, we need to pick out a variable from the URL of the current page and use it to generate the URL of the target page.
1. [urls.py] Models *Banker* and *Iaccount* are related as One-to-Many so if we are creating an *Iaccount* we cannot usually determine the *Banker* object to return to. In this example, URL1 contains the variable `iid` - the primary key to the Banker object; this will render a create form. We want to be able to reference URL2 from this form.
2. [views.py: get_initial] We can access the variable we want with `self.kwargs['iid']` and use it to set the initial value of the `ident` fields which links back to the *Banker* object
3. [views.py: get_success_url] In the same way we can pass the value into the form's *success_url* to point at URL2
4. [template] In the template, we can also access the variable now as `form.ident.value` so we can construct a *Go Back* link to URL2
Thanks to Thomas Orozco for leading the way.
In Django 1.5 url tags require you to pass in the name of the url as a string.
So where you used to be able to do this {% url home_page %} you now have to do this {% url 'home_page' %}
Upgrading an old project can be a pain, so here is a snippet for a py file that will update all your url tags.
Just put it in a py file in your root directory and execute it.
The error you get otherwise is:
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
[code]
{% get_video_urls url as url_object %}
or get object attribute:
{% get_video_urls obj "url" as url_object %}
{{ url_object }} original url
{{ url_object.video_id }} original url or video_id
{{ url_object.resource }} youtube, vimeo, None
{{ url_object.iframe_url }} original url or iframe_url
{{ url_object.js_api_url }} original url or js_api_url
[/code]
This middleware redirects HTTP requests to HTTPS for some specified URLs, in the same way as [85](http://djangosnippets.org/snippets/85/). It also changes the `url` template tag to use the `https` scheme for the same URLs. For example, if you have the following URL pattern:
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'https': True})
then the template:
{% from future import url %}
{% url 'django.contrib.auth.views.login' %}
will render:
https://host.example.com/accounts/login/
and any plain HTTP requests to /accounts/login get redirected to HTTPS. URL patterns not marked with `'https': True` remain unaffected.
Notes:
* The HttpRequest object must be present in the template context as `request`, so add `django.core.context_processors.request` to `TEMPLATE_CONTEXT_PROCESSORS` and make sure to use `RequestContext`.
* This snippet overrides the existing `url` template tag. Remove the last line and register the new `url` function properly, as a separate tag, if this makes you unhappy. You'd then have to change your templates to use it.
* It would be nicer to change the way reverse look-ups behave instead of changing only the `url` template tag, but the URL resolver, and the `reverse` function, know nothing about requests, so have no way to find the correct host name.
I created this template filter to be able to use get_absolute_url in an email template.
Save the code into /templatetags/navigation.py
Use like this:
{% load navigation %}
{{ instance.get_absolute_url|siteabsoluteurl:request }}
I'm working on a Project where on certain places I need absolute URL's, in development mode I need the port 8000 added to any absolute url.
This piece of work, took me some time to figure out. Couldn't find something similiar on the net, it's based on Code from the Python urlparse module.
You can change the "settings.PORT" part to "settings.DEBUG == True" if you like, and so on.
META: replace parameters in URL, edit parameters in URL, edit URL, urlparse
Default URL handler allows views to be loaded without defining them in the urls.py. Views will therefore be loaded based on the pattern of the browser url. For example http://host/app_name/view_name will load project_name.app_name.views.view_name. Though I would not used this in production, it can be used to speed-up development.