Login

Snippets by shellsage

Snippet List

ScriptPrefixMiddleware

Adds http://hostname or https://hostname before every URL generated by a Django url function. **Example:** Normally, something like YourModel().get_absolute_url() would return `/2009/09/02/slug`. However, this is not an absolute URL, because it does not include an HTTP schema or host. With this middleware, YourModel().get_absolute_url() will return `http://yourdomain.com/2009/09/02/slug`. This will also work for calls to reverse() or the {% url %} template tag. **Installation:** Drop this code into yourproject/middleware/scriptprefix.py. **Usage:** In your settings.py, add: MIDDLEWARE_CLASSES = ( # ... 'yourproject.middleware.scriptprefix.ScriptPrefixMiddleware', # ... )

  • url
  • domain
  • get_absolute_url
  • host
  • set_script_prefix
Read More

shellsage has posted 1 snippet.