2016-08-03 20 views
2

プロジェクトはWindowsのpycharmで問題なく動作しました。django deploy- ImproperlyConfigured:SECRET_KEY設定が空であってはなりません。

私はubuntu14.04とapache2に入れています。私は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. 

を実行すると

は、私も自分のmanage.pywsgi.pyを変更しようとしました。マイフォルダには、次のとおりです。私のmanage.pyで

Web-Interaction-APP 

-manage.py 

-seetings.py 

*apache(folder) 

     -wsgi.py 

*project(folder) 

私wsgi.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) 

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() 
+0

私はあなたの誤植seetings.pyがエラーではないと仮定していますか? Web-Interaction-APPはフォルダです(あなたの 'settings.py'ファイルを含んでいる必要があります)。 – YPCrumble

+0

ようこそスタックオーバーフロー!私はあなたの問題を推測できる限りあなたの質問を編集しました。しかし、コードや説明を追加することで、より多くの人々がその知識を持つ人に見られるようになります。特定の問題を特定するために必要な場合は、特定のエラーメッセージを編集してください。がんばろう! – manetsus

答えて

0

とき、あなたのDJANGO_SETTINGS_MODULE path is incorrectこのエラーが一般的です。

python manage.py runserver 8000を実行すると、manage.pyが使用されています。この設定はDJANGO_SETTINGS_MODULEsettingsです。あなたのルートディレクトリにsettings.pyを持っていることは表示されませんので、manage.pyでこの行:

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

はなるはずです:

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

あなたwsgi.pyファイルを持っているよう。

+0

私はこれを試しました。しかし、それは私の問題を解決するものではありません。それはWeb-Interaction-APPを見つけることができませんでした。設定 – KKlalala

+0

@FrancicaZhao私のコメントが見られましたか? Web-Interaction-APPはsettings.pyファイルを含むフォルダですか?そのsettings.pyファイルはあなたのベースのsettings.pyファイルがあればそれをインポートしますか?あなたの通常のsettings.pyファイルはどこにありますか?あなたのsettings.pyファイルの1つに 'SECRET_KEY'設定が含まれていますか? – YPCrumble

+0

Web-Interaction-APPはsettings.pyファイルを含むフォルダです。そしてそれは基本的なsetting.pyです。 SECRET_KEYも含まれます。フォルダはWindows上で正常に動作し、ApacheとUbuntuで動作しません。それはプログラム自体の代わりにシステム設定の問題だと思いますか? – KKlalala

0

たぶん、あなたの設定ファイルに、あなたがシェルを開いて、ENV変数を使用してSECRET_KEYを設定していると、ちょうど:

export SECRET_KEY='test_key' 

その後、再びサーバーを実行してみてください。

関連する問題