1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from django.core.urlresolvers import set_script_prefix
class ScriptPrefixMiddleware(object):
"""
Set the script prefix for all requests.
Essentially this adds the current request host to all calls to
get_absolute_url(). Much more convenient than adding the schema and
domain manually everywhere.
"""
def process_request(self, request):
schema = 'http://'
if request.is_secure():
schema = 'https://'
host = request.get_host()
if host:
set_script_prefix('%s%s' % (schema, host))
|
More like this
- Create short URL redirects for site urls. by matt.geek.nz 2 years, 12 months ago
- AddThis Social Networking TemplateTag by yeago 3 years, 1 month ago
- Super User Conditional Page Exception Reporting by zbyte64 3 years, 6 months ago
- Simple Age Verification Middleware by eculver 2 years, 6 months ago
- Saving passwords for other services (semi-)securely in a database by equanimity 2 years, 11 months ago
Comments