Log in

How i can production ?

  • 19 Jun

I have 500 error with example from github
debug = True not work

nitelyEsteban Castro Borsani
  • 19 Jun

If debug = True does not work, then the request is not hitting Django. The issue must be elsewhere. Could be anything, Nginx config, gunicorn, uWSGI, or whatever web server or proxy you are running in front of django. Check the logs.

  • 20 Jun

I need settings for apache. Help me.

  • 20 Jun

I need settings for apache and wsgi for start server

nitelyEsteban Castro Borsani
  • 20 Jun

There are official docs for apache[0] . DigitalOcean has some docs that are useful for any VPS [1] in case you are running one.

[0] https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/
[1] https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

  • 1
  • 20 Jun

i do it.
but in apache log: The SECRET_KEY setting must not be empty.

in prod.py Secret_key is full

  • 20 Jun

may be apache dont see settings django project?

  • 20 Jun

in wsgi.py i add: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.project.settings.prod_local")

in apache log: ImportError: No module named prod_local
but in folder settings prod_local.py exist

nitelyEsteban Castro Borsani
  • 1
  • 20 Jun

Try

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.prod_local")

and

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.example.project.settings.prod_local")

This last one sound like it may be the winner according to django docs. Just replace project_name by your actual project name. Remember to restart Apache afterwards.

If that does not work then try to generate the path with this:

import os

# Very crappy code. There's probably a better way by using importlib, but meh
MODULE_PATH = '%s.settings.prod_local' % '.'.join(os.path.split(os.path.dirname(__file__))).strip('.')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", MODULE_PATH)

If that does not work then you'll have to find what's the relative path to wsgi.py. You can do it by raising an exception so it'll be printed in the apache logs. This is pretty much the same as above. You can create the import path later.

import os
raise Exception(os.path.dirname(__file__))

There's probably a way to set the working dir in Apache, but no idea.

Be aware that mod_wsgi may or may not modify the Python sys.path, so you may want to print that and find places from where you can import the settings. If nothing works then raise an exception passing sys.path and share the output here, so I can help you from there.

import sys
raise Exception(str(sys.path))

Remember to restart Apache after each change you make.

  • 21 Jun

ImportError: Import by filename is not supported.

nitelyEsteban Castro Borsani
  • 1
  • 21 Jun

When doing what? Can you share the output of __file__ and sys.path (either by running a debugger or raising an exception)?

Reply