[英]Gunicorn wouldn't run Django with WSGI
我正在嘗試使用gunicorn運行我的django項目,但出現錯誤。 為了測試,我通過運行以下命令創建了所有新內容:
virtualenv test_gunicorn
source test_gunicorn/bin/activate
pip install django gunicorn
cd test_gunicorn/
mkdir projects
cd projects/
django-admin startproject test_gunicorn
cd test_gunicorn/
gunicorn test_gunicorn/wsgi:application
但是仍然遇到與原始項目完全相同的錯誤。 下面是錯誤:
[2015-07-13 14:22:33 +0000] [9122] [INFO] Starting gunicorn 19.3.0
[2015-07-13 14:22:33 +0000] [9122] [INFO] Listening at: http://127.0.0.1:8000 (9122)
[2015-07-13 14:22:33 +0000] [9122] [INFO] Using worker: sync
[2015-07-13 14:22:33 +0000] [9127] [INFO] Booting worker with pid: 9127
[2015-07-13 14:22:33 +0000] [9127] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
self.wsgi = self.app.wsgi()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
ImportError: Import by filename is not supported.
Traceback (most recent call last):
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
worker.init_process()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
self.wsgi = self.app.wsgi()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
ImportError: Import by filename is not supported.
[2015-07-13 14:22:33 +0000] [9127] [INFO] Worker exiting (pid: 9127)
Traceback (most recent call last):
File "/home/tahir/official/virtualenvs/test_gunicorn/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
super(Application, self).run()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 174, in run
self.manage_workers()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 541, in spawn_workers
time.sleep(0.1 * random.random())
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 214, in handle_chld
self.reap_workers()
File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
這是pip freeze
輸出:
Django==1.8.3
gunicorn==19.3.0
我在這里做錯什么了嗎,或者Django或gunicorn有問題?
錯誤告訴您正在傳遞文件路徑,而不是Python模塊路徑。 您的gunicorn調用應為:
gunicorn test_gunicorn.wsgi:application
您應該以gunicorn test_gunicorn.wsgi:application
啟動gunicorn(請注意,在test_gunicorn
和wsgi
之間使用圓點而不是斜線)。 基本上,語法與您在Python中編寫import
語句時的語法相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.