a way to have django SITEURL constant in settings.py
NickName:Hafiz Ask DateTime:2012-09-09T02:53:22

a way to have django SITEURL constant in settings.py

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?

Copyright Notice:Content Author:「Hafiz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12333548/a-way-to-have-django-siteurl-constant-in-settings-py

More about “a way to have django SITEURL constant in settings.py” related questions

a way to have django SITEURL constant in settings.py

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 ...

Show Detail

Proper way to import a single Django settings constant to avoid the full settings import overhead?

From Django - Difference between import django.conf.settings and import settings, I understand the accepted way to import the settings file: from django.conf import settings I've also read Good o...

Show Detail

In Django, how to use settings.py constant from a static file?

I have a static file that I use in my template. I need to hide some information in this file code but I normally use settings.py constants to do that. How can I instance a settings.py constant ...

Show Detail

Django: Accented characters in settings.py are broken when accessed in a view

I have accented characters in my settings.py that I access in a view using getattr(settings, 'MY_CONSTANT_NAME', []) but the getattr() call return broken characters (for example, "ô" become: "\xc3\...

Show Detail

How to create a settings.py file for an existing django project

It seems to be a Django best practice to add the settings.py file to the ignore list of the version control system. But how does one start to set up a project when the settings.py file was not incl...

Show Detail

Relative path in settings.py in django

for various settings(MEDIA_ROOT,TEMPLATE_DIRS) in setting.py it is instructed to give absolute path.I have configured apache with mod_wsgi.I have a wsgi script in the folder named apache that redir...

Show Detail

Import model in Django's settings.py

I'm trying to define a constant with the value of model's class in the settings.py to provide a dynamically-defined FK for one of my models: from catalog.models import Product PRODUCT_MODEL = Prod...

Show Detail

Use Django logging facility in settings.py

My settings.py contains a lot of imports in try/catch blocks like: try: import gcframe except ImportError: # log gcframe is not available pass etc. I'd like to use Django logger to log

Show Detail

Using the correct settings constant in Django view

I am moderatly experienced with Django and am setting up a new project using the now recommended "multiple settings files" pattern. Each settings.py file will import a base settings.py and then ove...

Show Detail

pytest-django Use env vars in settings.py

I have an api in Django that uses quite a few environment variables. The idea is to add pytest-django to test all its functionalities (I know it would have been smarter to build the tests together ...

Show Detail