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 8492907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:51:35+00:00 2026-06-10T22:51:35+00:00

I am from PHP background, and I know that constants can be accessed at

  • 0

I am from PHP background, and I know that constants can be accessed at most of places in a framework and I think it is same in django as well. I tried to have that URL too in django but I tried to have it from django.contrib. I tried to utilize django’s Site class and imported that. But the problem is that at time of loading settings.py I can’t import any django contrib. file.

So how can I have SITE URL automatically that I can use anywhere, in template as well as at other places.What is the best way to do so? Do any python utility can do so?

  • 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-10T22:51:36+00:00Added an answer on June 10, 2026 at 10:51 pm

    Whatever you define in your settings.py, for example

    SITE_URL = 'http://www.mydomain.com'
    

    Can be accessed in all your Django related code with:

    from django.conf import settings #this imports also your specific settings.py
    
    print settings.SITE_URL
    

    Or just Site.objects.get_current().domain

    If you want to be able to access it in the templates, you make your own template context processor. Put this in my_project/content_processor.py

    from django.conf import settings
    def my_site_url(request):
        return {
            'SITE_URL': settings.SITE_URL,
        }
    

    Or if you want it Dynamic:

    from django.conf import settings
    def my_site_url(request):
        return {
            'SITE_URL': Site.objects.get_current().domain,
        }
    

    And add it to your TEMPLATE_CONTEXT_PROCESSORS variable in settings.py. It should look similar to that afterwards:

    TEMPLATE_CONTEXT_PROCESSORS =("django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "my_project.context_processors.my_site_url",
    )
    

    and finished.

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

Sidebar

Related Questions

I'm from a PHP background. All I know is that web server handles the
Coming from a PHP background, I'm used to writing small functions that return a
I'm moving from a PHP background into Django development via python, mostly for the
Im from a PHP background so I know this is possible. I'm not sure
I come from PHP background and am used to doing var_dump , echo and
I am from PHP background and want to give path to STATICFILES_DIRS in settings.py
I come from a php background and in php, there is an array_size() function
I am coming from a PHP background and I am familiar with OOP concepts,
I come from a PHP background and I'm just getting my teeth into some
I'm not too used to ORM mapping, having come from a PHP background. I'm

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.