2

The project worked fine on windows pycharm.

Now i am putting it on ubuntu14.04 and apache2.

When i run python manage.py runserver 8000

Traceback (most recent call last):   File "manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 195, in fetch_command
    klass = load_command_class(app_name, subcommand)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/commands/runserver.py", line 16, in <module>
    from django.db.migrations.executor import MigrationExecutor   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/executor.py", line 7, in <module>
    from .loader import MigrationLoader   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/loader.py", line 10, in <module>
    from django.db.migrations.recorder import MigrationRecorder   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 12, in <module>
    class MigrationRecorder(object):   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 26, in MigrationRecorder
    class Migration(models.Model):   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 27, in Migration
    app = models.CharField(max_length=255)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/models/fields/__init__.py", line 1072, in __init__
    super(CharField, self).__init__(*args, **kwargs)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/models/fields/__init__.py", line 166, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)   File "/var/www/Web-Interaction-APP/settings.py", line 8, in <module>
    application = get_wsgi_application()   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup()   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/__init__.py", line 17, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)   File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 120, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

I have also tried to change my manage.py and wsgi.py. My folder is:

Web-Interaction-APP

-manage.py  

-seetings.py

*apache(folder)

       -wsgi.py

 *project(folder)

in my manage.py:

#!/usr/bin/env python
#This file runs the server for this application from command line.
import os, sys

#Executes the code in the following condition if the program is run directly. 
#(Source: http://stackoverflow.com/questions/419163/what-does-if-name-main-do)
if __name__ == "__main__":
    #Refers to the path of this django project's settings module.
    #(DJANGO_SETTINGS_MODULE is an environment variable to module import path.)
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

    from django.core.management import execute_from_command_line
    #Executes the django project.
    execute_from_command_line(sys.argv)

In my wsgi.py:

import os, sys
# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Web-Interaction-APP.settings")


# Add the path to 3rd party django application and to django itself.
sys.path.append('/home/zhaojf1')
os.environ['DJANGO_SETTINGS_MODULE'] = '10.231.52.XX.apache.override'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
KKlalala
  • 965
  • 1
  • 13
  • 23
  • I'm assuming your typo seetings.py is not the error? Is Web-Interaction-APP a folder (it should be and should include your `settings.py` file). – YPCrumble Aug 04 '16 at 00:14
  • Welcome to Stack Overflow! I edited your question as far as I could guess your problem. However, add code and description so that more people with knowledge of the subject will see it. Please edit in the specific error-message you're encountering in case that's necessary to identify the specific problem. Good Luck! – Enamul Hassan Aug 05 '16 at 23:49

2 Answers2

2

Maybe in your settings file, you are setting the SECRET_KEY using a ENV variable, open a shell and just:

 export SECRET_KEY='test_key'

Then, try to run your server again.

levi
  • 22,001
  • 7
  • 73
  • 74
1

This error is common when your DJANGO_SETTINGS_MODULE path is incorrect.

When you run python manage.py runserver 8000 you are using manage.py which is settings your DJANGO_SETTINGS_MODULE to settings. It doesn't appear that you have a settings.py in your root directory, so this line in manage.py:

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

should become:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Web-Interaction-APP.settings")

as you have in your wsgi.py file.

Community
  • 1
  • 1
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • I tried this. But it does not fix my issue. It said can't find Web-Interaction-APP.settings – KKlalala Aug 04 '16 at 15:10
  • @FrancicaZhao did you see my comment? Is Web-Interaction-APP a folder that includes a settings.py file? Does that settings.py file import your base settings.py file if that exists? Where is your regular settings.py file in the directory? Does one of your settings.py files include a `SECRET_KEY` setting? – YPCrumble Aug 04 '16 at 15:18
  • Web-Interaction-APP IS a folder that includes a settings.py file. And it is the base setting.py. it also include SECRET_KEY. The folder works fine on windows and not working with apache and ubuntu. Do you think it's a problem of the system config instead of the program itself? – KKlalala Aug 04 '16 at 16:02
  • @FrancicaZhao so has the error changed to say ` can't find Web-Interaction-APP.settings`? If so post that error. – YPCrumble Aug 04 '16 at 16:08
  • I made a related mistake. In the shell I was using, I `source`d the file containing all environment variables (including `DJANGO_SETTINGS_MODULE`), but then had to actually execute `export DJANGO_SETTINGS_MODULE` for it to be passed on to `python manage.py`. – Daniel Werner Jun 03 '19 at 17:36