django-settings

Why is Django throwing error "DisallowedHost at /"?

Why is Django throwing error "DisallowedHost at /"? Question: I am setting up my own Django server using this Digital Ocean tutorial. I created the Django framework following each step, and ran the server using this command: ./manage.py runserver 0.0.0.0:8000 When I tried to visit the IP at port 8000, the following error was shown: …

Total answers: 6

How can I get the email configuration from the DB?

How can I get the email configuration from the DB? Question: What I need is to take the email configuration like EMAIL_HOST_USER, EMAIL_HOST, EMAIL_PORT, etc. From my database and then pass that values to the email configuration in the settings.py file. Is this possible? and if is, how can I do it? Asked By: M. …

Total answers: 2

Page not found 404 Django media files

Page not found 404 Django media files Question: I am able to upload the files to media folder( ‘/peaceroot/www/media/’) that I have set up in settings.py as below MEDIA_ROOT = ‘/peaceroot/www/media/’ MEDIA_URL = ‘/media/’ But through admin I tried to access the uploaded image file http://localhost:8000/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg then I am getting 404 error. The file exists …

Total answers: 6

Django: "No module named context_processors" error after reboot

Django: "No module named context_processors" error after reboot Question: I have a Django site that works on my PC, and was working briefly on my server after loading it on. I noticed my server had Django 1.6 and I upgraded to 1.8. After rebooting, none of the pages on my site load and I get …

Total answers: 5

how can I check database connection to mysql in django

how can I check database connection to mysql in django Question: how can I do it? I thought, I can read something from database, but it looks too much, is there something like?: settings.DATABASES[‘default’].check_connection() Asked By: doniyor || Source Answers: All you need to do is start a application and if its not connected it …

Total answers: 8

ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings Question: I was trying to configure my Django project to deploy to Heroku. I am getting the following error and I don’t really know how to fix it. Here is the full traceback and error: 22:46:15 web.1 | Traceback (most …

Total answers: 13

how to check DEBUG true/false in django template – exactly in layout.html

how to check DEBUG true/false in django template – exactly in layout.html Question: I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not. I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like, btw …

Total answers: 1

Django default cache

Django default cache Question: I’m importing and using cache as this: from django.core.cache import cache cache.add(‘a’,’b’,60) I haven’t defined any settings for the cache in settings.py ,then where does this cache come from and where is it stored. Django documentation says: "This object is equivalent to caches[‘default’]", but what is the default ? Asked By: …

Total answers: 3

Django: Check if settings variable is set

Django: Check if settings variable is set Question: Here is an example of what I’m trying to achieve. The desired effect is that a particular feature should take effect if and only if its relevant setting exists is defined. Otherwise, the feature should be disabled. settings.py: SOME_VARIABLE = ‘some-string’ ANOTHER_VARIABLE = ‘another-string’ random_code_file.py: from django.conf …

Total answers: 1

dynamically loading django apps at runtime

dynamically loading django apps at runtime Question: Is it possible to dynamically load Django apps at runtime? Usually, apps are loaded at initialization, using the INSTALLED_APPS tuple in settings.py. However, is it possible to load additional apps at runtime? I am encountering this issue in different situations. One situation, for example, arises during testing, when …

Total answers: 5