Login

Tag "site"

Snippet List

Add site info to request context

Sometimes you want to generate a **really** absolute URL, but the built-in url tag only generates a URL relative to the current domain. This context processor adds the extra information needed to the request context, so you can generate an absolute URL in a template like so: `{{ protocol }}://{{ domain }}{% url someview %}` This is similar to how the password reset email from contrib.auth generates the full URL in the email. Save this somewhere as context_processors.py (or add to existing file if you have one), and add context_processors.site to your TEMPLATE_CONTEXT_PROCESSORS setting.

  • contextprocessor
  • domain
  • site
Read More

Default to current/all sites in admin (updated!)

This code sets the default sites for a sites ManyToMany property to `Site.objects.all()`, which makes sure you don't have to bother setting it for each item on a site. This could easily be changed to `Site.objects.get_current()` to use the current site as default.

  • admin
  • sites
  • default
  • site
  • current
  • all
Read More

2 snippets posted so far.