How to solve “Page not found (404)” error in Django?

You are getting the 404 because you haven’t defined a url pattern for http://127.0.0.1:8000/ yet. You should be able to view the admin site at http://127.0.0.1:8000/admin/ and your food posts at http://127.0.0.1:8000/foodPosts/. To add a url pattern for the homepage, uncomment the following entry in your urls.py, and replace homefood.views.home with the path to the … Read more

Simple Log to File example for django 1.3+

I truly love this so much here is your working example! Seriously this is awesome! Start by putting this in your settings.py LOGGING = { ‘version’: 1, ‘disable_existing_loggers’: True, ‘formatters’: { ‘standard’: { ‘format’ : “[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s”, ‘datefmt’ : “%d/%b/%Y %H:%M:%S” }, }, ‘handlers’: { ‘null’: { ‘level’:’DEBUG’, ‘class’:’django.utils.log.NullHandler’, }, ‘logfile’: { ‘level’:’DEBUG’, … Read more

dynamically loading django apps at runtime

Update for Django 1.8 on how to load an app that is not loaded yet from collections import OrderedDict from django.apps import apps from django.conf import settings from django.core import management new_app_name = “my_new_app” settings.INSTALLED_APPS += (new_app_name, ) # To load the new app let’s reset app_configs, the dictionary # with the configuration of loaded … Read more

Django give Error 500 for all static files like CSS and Images, when DEBUG is False

This is expected behavior. Django does not serve static files or media files in production. You should configure nginx, etc. to serve files. As is specified in the Static file development view section of the documentation: This view will only work if DEBUG is True. That’s because this view is grossly inefficient and probably insecure. … Read more

How to set up a PostgreSQL database in Django

You need to install psycopg2 Python library. Installation Download http://initd.org/psycopg/, then install it under Python PATH After downloading, easily extract the tarball and: $ python setup.py install Or if you wish, install it by either easy_install or pip. (I prefer to use pip over easy_install for no reason.) $ easy_install psycopg2 $ pip install psycopg2 … Read more

How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files?

I think the following should work, and be simpler than Mandx’s method, although it’s very similar: Create a s3utils.py file: from storages.backends.s3boto import S3BotoStorage StaticRootS3BotoStorage = lambda: S3BotoStorage(location=’static’) MediaRootS3BotoStorage = lambda: S3BotoStorage(location=’media’) Then in your settings.py: DEFAULT_FILE_STORAGE = ‘myproject.s3utils.MediaRootS3BotoStorage’ STATICFILES_STORAGE = ‘myproject.s3utils.StaticRootS3BotoStorage’ A different but related example (that I’ve actually tested) can be seen in … Read more

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

I figured that the DJANGO_SETTINGS_MODULE had to be set some way, so I looked at the documentation (link updated) and found: export DJANGO_SETTINGS_MODULE=mysite.settings Though that is not enough if you are running a server on heroku, you need to specify it there, too. Like this: heroku config:set DJANGO_SETTINGS_MODULE=mysite.settings –account <your account name> In my specific … Read more