我正试图开始我的第一个Django动力项目。我重新编译了一个现有的项目。迁移已完成,没有任何错误,开发服务器也运行正常。当我试图用uWSGI服务器运行项目时,挑战就来了。项目环境如下:python2.7、Django 1.9.5、uWSGI 2.0.10 LTS。我也查过类似的问题,但到目前为止没有一个问题能解决我的问题。这是我的uWSGI日志
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_本地.py文件
^{pr2}$这是我的缓存.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())
这是我的模型.py,完整的代码太大,不能发布,所以我只发布它的例外情况,如果需要,我会发布特定的行代码。在
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
也可以看到设置.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',
)
我不知道我哪里弄错了,如果有人指点我会很感激的。提前谢谢。。。。在
我想您的导入
from smsapp import models
不正确。在看看这个问题,它可能会有帮助:Django Import Class From models.py
相关问题 更多 >
编程相关推荐