我使用virtualenv作为django。
在cmd运行python manage.py runserver。
在这个网站中,像importError这样的问题大多数都没有 解决。
我的问题,有一天它可以最终得到解决。 > _<
(virtual_env_django_1.7)cundi@cundideAir ~/P/Forum> python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/cundi/virtual_env_django_1.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/cundi/virtual_env_django_1.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/cundi/virtual_env_django_1.7/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/cundi/virtual_env_django_1.7/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/cundi/virtual_env_django_1.7/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/cundi/PycharmProjects/Forum/accounts/models.py", line 6, in <module>
from my_forum.models import Topic, Post
File "/Users/cundi/PycharmProjects/Forum/my_forum/models.py", line 9, in <module>
from utils.bbs_utils import get_delta_time
File "/Users/cundi/PycharmProjects/Forum/utils/bbs_utils.py", line 6, in <module>
from utils import conf
File "/Users/cundi/PycharmProjects/Forum/utils/conf.py", line 4, in <module>
from accounts.models import ForumProfile
ImportError: cannot import name ForumProfile
&#13;
使用google搜索类似的Error.But还没有解决它。
这是我的accounts.models.py文件。
可能有问题。
class BaseSiteUser(models.Model):
# you can get user info like this: user.base_site_user_set.all()[0]
user = models.OneToOneField(User)
class Profile(BaseSiteUser):
nickname = models.CharField(max_length=12, blank=True, null=True)
user_avatar = models.BooleanField(default=True)
avatar_img = models.ImageField(blank=True, null=True, upload_to='avatar', default='avatar/d_avatar.png')
description = models.TextField(null=True, blank=True)
address = models.CharField(max_length=50, null=True, blank=True)
phone = models.CharField(max_length=11, null=True, blank=True)
born_date = models.DateField(
verbose_name=u'出生日期', null=True, blank=True, default=None)
date_created = models.DateField(null=True, blank=True, verbose_name=u'账户创建日期', auto_now_add=True)
class ForumProfile(Profile):
favorite = models.ManyToManyField(Topic, verbose_name='fav_user', related_name='fav', blank=True)
vote = models.ManyToManyField(Topic, verbose_name='vote_user', related_name='vote', blank=True)
coins = models.IntegerField(default=0, blank=True, null=True)
location = models.CharField(max_length=20, blank=True, null=True)
last_activity = models.DateTimeField(auto_now_add=True)
last_posttime = models.DateTimeField(auto_now_add=True)
signature = models.CharField(max_length=128, default='This guy is lazy that nothing to leave')
website = models.URLField(blank=True, null=True)
&#13;
这是model.py文件的一些代码段。希望它会有所帮助。
settings.py有问题吗?
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '1-ygln+^^7=5=c)u3#2ozm#jiu)6=65m((rg09pwl069242@vc'
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'accounts',
'my_forum',
'utils',
'blog',
'django.contrib.humanize',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'Forum.urls'
WSGI_APPLICATION = 'Forum.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static', 'static_files'),)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'templates/public'),
)
MAX_UPLOAD_SIZE = "524288"
EMAIL_USE_TLS = True
EMAIL_HOST = ''
EMAIL_PORT = 465
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),)
&#13;