djangosnippets.org: Latest snippets tagged with 'url'https://djangosnippets.org/tags/url/2019-10-17T10:14:57.330299-05:00a better Django Slug Unique Generator
2019-10-17T10:14:57.330299-05:00ParsaFakharhttps://djangosnippets.org/snippets/10680/<p>let say the user chooses the name "Elsa Frozen"
now his slug would be "Elsa-Frozen-5"</p>
<p>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</p>
Freely redistributableMixin to set url kwargs to Class Based Views
2017-06-21T14:42:33.324578-05:00dimkoughttps://djangosnippets.org/snippets/10612/<p>This mixin is for class based views. Kwargs passed from url patterns to views via the dispatch method.</p>
Freely redistributableGoogle URL Shortner using Python requests
2015-05-17T20:31:21.974850-05:00akshayw39https://djangosnippets.org/snippets/10486/<p>This code can convert a url to short url using google URL Shortener API https://developers.google.com/url-shortener/v1/getting_started </p>
Freely redistributableInherit the standard url tag to include domain name
2013-12-22T15:27:52.497281-06:00atodorov-otbhttps://djangosnippets.org/snippets/3013/<p>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.</p>
<p>See my blog for the background story:
<a href="http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/">http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/</a></p>
Freely redistributableUrl query string template tag (qurl)
2013-09-06T13:26:35.645217-05:00priccohttps://djangosnippets.org/snippets/2990/<p>qurl is a tag to append, remove or replace query string parameters from an url (preserve order)</p>
Freely redistributableAccessing URL variable from within a Form
2013-09-01T21:31:55.098437-05:00blacktavhttps://djangosnippets.org/snippets/2987/<p><strong>Use case:</strong></p>
<p>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 …</p>
Freely redistributableUpgrade django url tags
2013-03-29T18:57:22.805475-05:00Craterdomehttps://djangosnippets.org/snippets/2905/<p>In Django 1.5 url tags require you to pass in the name of the url as a string.</p>
<p>So where you used to be able to do this {% url home_page %} you now have to do this {% url 'home_page' %}</p>
<p>Upgrading an old project can be a pain, …</p>
Freely redistributableconvert youtube url for iframe, js api
2013-03-22T03:21:01.990071-05:00ivanffhttps://djangosnippets.org/snippets/2902/<p>[code]
{% get_video_urls url as url_object %}</p>
<p>or get object attribute:</p>
<p>{% get_video_urls obj "url" as url_object %}</p>
<p>{{ url_object }} original url</p>
<p>{{ url_object.video_id }} original url or video_id</p>
<p>{{ url_object.resource }} youtube, vimeo, None</p>
<p>{{ url_object.iframe_url }} original url or iframe_url</p>
<p>{{ url_object.js_api_url }} original url or js_api_url …</p>
Freely redistributableGet active page's url by another language (templatetag)
2013-01-06T10:28:40.947626-06:00muratcorluhttps://djangosnippets.org/snippets/2875/<p>Usage:</p>
<pre><code>{% load helper_tags %}
{% get_available_languages as languages %}
{% for lang_code, lang_name in languages %}
<link rel="alternate" hreflang="{{ lang_code }}" href="{% change_lang lang_code %}">
{% endfor %}
</code></pre>
Freely redistributableUse express.js like url patterns
2012-11-19T08:05:37.969434-06:00ekinertachttps://djangosnippets.org/snippets/2848/<p>Sometimes using regex is a huge pain</p>
Freely redistributableSave an image to ImageField from URL
2012-10-27T22:46:09.646734-05:00ekinertachttps://djangosnippets.org/snippets/2838/<h4>this is the right and working way</h4>
Freely redistributableHTTPS redirections middleware with updated URL template tag
2012-10-19T11:12:48.629453-05:00xlqhttps://djangosnippets.org/snippets/2833/<p>This middleware redirects HTTP requests to HTTPS for some specified URLs, in the same way as <a href="http://djangosnippets.org/snippets/85/">85</a>. It also changes the <code>url</code> template tag to use the <code>https</code> scheme for the same URLs. For example, if you have the following URL pattern:</p>
<pre><code>url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'https': True})
</code></pre>
<p>then the template: …</p>
Freely redistributabletemplate filter to include protocol and domain in absolute urls
2012-07-04T15:50:48.638153-05:00czerhttps://djangosnippets.org/snippets/2783/<p>I created this template filter to be able to use get_absolute_url in an email template.</p>
<p>Save the code into /templatetags/navigation.py</p>
<p>Use like this:</p>
<pre><code>{% load navigation %}
{{ instance.get_absolute_url|siteabsoluteurl:request }}
</code></pre>
Freely redistributableadd port from settings file to an url
2012-06-22T00:12:59.174640-05:00sebnapihttps://djangosnippets.org/snippets/2776/<p>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.</p>
<p>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 …</p>
Freely redistributableDefault URL handler
2011-04-19T01:34:21.659657-05:00solartichttps://djangosnippets.org/snippets/2417/<p>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. </p>
Freely redistributable