Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7957127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:08+00:00 2026-06-04T04:12:08+00:00

Using the Django-auth application (Django version 1.3), I want to have my login page

  • 0

Using the Django-auth application (Django version 1.3), I want to have my login page go to https://mysite.com/login/. Currently, I’m using:

# urls.py
from django.contrib.auth.views import login
urlpatterns = patterns('', url(r'^login/$', login, name='login-view'),)

# navbar.html
<li id="nav-login"><a href="{% url login-view %}" ><b>Login</b></a></li>

which works nicely, but goes to http://mysite.com/login/.

Is there some way to tell Django-auth what prefix (https) to use, when it reverses the view name? I’ve read the entire manual page, and haven’t found anything that covers it. Or maybe some way to tell the url tag to go to https?

Or is the only option to specify the entire URL manually? I hope not 🙂 And given how powerful Django has been so far, I can’t believe it wouldn’t have that ability – I must be overlooking it. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:12:09+00:00Added an answer on June 4, 2026 at 4:12 am

    Set OS environmental variable HTTPS to on

    You need to enable the OS environmental variable HTTPS to 'on' so django will prepend https to fully generated links (e.g., like with HttpRedirectRequests). If you are using mod_wsgi, you can add the line:

    os.environ['HTTPS'] = "on"
    

    to your wsgi script. You can see the need for this by reading django/http/__init__.py:

    def build_absolute_uri(self, location=None):
        """
        Builds an absolute URI from the location and the variables available in
        this request. If no location is specified, the absolute URI is built on
        ``request.get_full_path()``.
        """
        if not location:
            location = self.get_full_path()
        if not absolute_http_url_re.match(location):
            current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
                                         self.get_host(), self.path)
            location = urljoin(current_uri, location)
        return iri_to_uri(location)
    
    def is_secure(self):
        return os.environ.get("HTTPS") == "on"
    

    Secure your cookies

    In settings.py put the lines

    SESSION_COOKIE_SECURE = True
    CSRF_COOKIE_SECURE = True
    

    and cookies will only be sent via HTTPS connections. Additionally, you probably also want SESSION_EXPIRE_AT_BROWSER_CLOSE=True. Note if you are using older versions of django (less than 1.4), there isn’t a setting for secure CSRF cookies. As a quick fix, you can just have CSRF cookie be secure when the session cookie is secure (SESSION_COOKIE_SECURE=True), by editing django/middleware/csrf.py:

    class CsrfViewMiddleware(object):
       ...
       def process_response(self, request, response):
           ...
           response.set_cookie(settings.CSRF_COOKIE_NAME,
                request.META["CSRF_COOKIE"], max_age = 60 * 60 * 24 * 7 * 52,
                domain=settings.CSRF_COOKIE_DOMAIN,
                secure=settings.SESSION_COOKIE_SECURE or None)
    

    Direct HTTP requests to HTTPS in the webserver

    Next you want a rewrite rule that redirects http requests to https, e.g., in nginx

    server {
       listen 80;
       rewrite ^(.*) https://$host$1 permanent;
    }
    

    Django’s reverse function and url template tags only return relative links; so if you are on an https page your links will keep you on the https site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using django-social-auth (https://github.com/omab/django-social-auth), with some success - logging in from Twitter and
I have a django application, using the basic userprofile extension of django.contrib.auth.user model. I
I'm using django.contrib.auth.views.login to log in users. When login is failed, the user and
I'm trying to store the user's ID in the session using django.contrib.auth.login . But
I am using django-social-auth for facebook login. I am able to login user using
I am using Django 1.3/Python 2.7. My application is using django.contrib.auth for User management.
I have a Django application that logs users in and out using the standard
I am using the standard User model (django.contrib.auth) which comes with Django. I have
I am using social_auth in my django application to use facebook connect. I have
Using django-social-auth to grab user data from facebook, it is returning a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.