私は最初のDjangoの動力プロジェクトを始めようとしています。私は既存のプロジェクトを再コンパイルしました。移行はエラーなしで完了し、開発サーバーも問題なく実行されます。課題は、uWSGIサーバーでプロジェクトを実行しようとするときです。プロジェクト環境は、Python 2.7、Django 1.9.5、uWSGI 2.0.10 LTSです。私は同様の質問をチェックしたが、これまでのところ私の問題は解決していない。ここに私のuWSGIログがあります。ここでPython - Django - uWSGI NameError:グローバル名 'models'が定義されていません
Traceback (most recent call last):
File "/home/admin/apps/smsapp/uwsgi_local.py", line 3, in <module>
from smsapp import cache
File "/home/admin/apps/smsapp/cache.py", line 3, in <module>
from smsapp import models
File "/home/admin/apps/smsapp/models.py", line 9, in <module>
from django.contrib.auth.models import User, UserManager, Permission
File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/contrib/auth/models.py", line 6, in <module>
from django.contrib.contenttypes.models import ContentType
File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 161, in <module>
class ContentType(models.Model):
File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (models.Model)
NameError: global name 'models' is not defined
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1c7fb60 pid: 3551 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3551)
spawned uWSGI worker 1 (pid: 3557, cores: 1)
spawned uWSGI worker 2 (pid: 3558, cores: 1)
spawned uWSGI worker 3 (pid: 3559, cores: 1)
私uwsgi_local.pyファイル
uwsgi_local.py
from uwsgidecorators import timer
from smsapp import cache
@timer(5)
def update_caches(signum):
cache.rebuild_cache()
が、これはこれは私のmodels.pyである私のcache.py
cache.py
from django.conf import settings
from smsapp import models
KEY_NAME = "blacklist"
def rebuild_cache():
opt, created = models.Option.objects.get_or_create(name="blacklist")
c = opt.content
r = c.splitlines()
pipe = settings.REDIS.pipeline(transaction=True)
pipe.delete(KEY_NAME)
for ln in filter(None, r):
ss = ln.strip().lower()
if ss:
pipe.sadd(KEY_NAME, ss)
pipe.execute()
def is_blacklisted(name):
"""
Checks if the app is blacklisted
@param name: app to check
@type name: str
@return: True if blacklisted, False otherwise
@rtype: bool
"""
return settings.REDIS.sismember(KEY_NAME, name.lower())
であり、完全なコードはとても投稿には大きすぎます私はそれの例外を投稿するだけです、私は特定の行コードを要求する場合は投稿します。
models.py
import base64
import logging
from datetime import timedelta, datetime
import re
import HTMLParser
from ago import human
from django.conf import settings
from django.contrib.auth.models import User, UserManager, Permission
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import AppRegistryNotReady
from django.db import models, connection
from django.db.models import Q
from django.db.models.signals import post_save
from django.db.utils import ProgrammingError
from django.dispatch import receiver
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django_countries.fields import CountryField
from smsapp import idgen, commands, cfields
logger = logging.getLogger(__name__)
DB_HTML_CACHE = "__htmlCache"
DB_HTML_VERSION = "__htmlVersion"
DB_CACHE_TIMEOUT = 30
また、私は、私はそれが間違って取得していますどこか分からないsettings.py
# Application definition
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django_extensions',
'django_countries',
'mobile_codes',
'bootstrap3',
'smsc',
'smsapp',
'django_admin_bootstrapped',
'django.contrib.admin',
)
のスナップを参照して、任意のポインタが理解されるであろう。事前に感謝....
おかげで、私はこの後、夕方見てみましょう。 – cbytes2
私はいくつかの進歩を遂げましたが、私はコマンドで – cbytes2
(django)[root @ devel uwsgi-2.0.10]#./uwsgi --http:8080 --chdir/home/admin/apps/smsapp --wsgi-file /home/admin/apps/smsapp/smsg/wsgi.py --chmod-socket = 666です。 – cbytes2