Django Runserver ImportError: No module named models
Django Runserver ImportError: No module named models
当我 运行 Django App 我得到以下错误:
Unhandled exception in thread started by <function wrapper at 0x7f8449a387d0>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/project/urls.py", line 10, in <module>
url(r'', include('web.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/web/urls.py", line 6, in <module>
from web import views, models
File "/root/soho-website/backend/web/views.py", line 19, in <module>
from captcha.models import CaptchaStore
ImportError: No module named models
但是,如果我在我的 urls.py 文件中注释以下行:url(r'', include('web.urls')),
我在其中定义了我的索引页面,我的应用程序可以正常工作。
我已经通过 Pip(验证码、Ckeditor、MySQL 等)正确安装了我的所有应用程序
详情:
- 我的项目名称:项目
- Django 版本:1.9.5
- Python 版本:2.7.6 [GCC 4.8.2] on linux2
urls.py 文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
# Website URLs
url(r'', include('web.urls')),
# Admin URLs
url(r'^admin/', include(admin.site.urls)),
)
base.py 文件(部分配置):
import os
from django.core.urlresolvers import set_urlconf
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ROOT_URLCONF = 'project.urls'
WSGI_APPLICATION = 'project.wsgi.application'
DOMAIN_URL = "http://MY_IP"
我的应用程序的结构是:
我的配置有什么问题?
更新
我已经使用 PIP INSTALL 正确安装了验证码。在我的 Installed_APPS 中,我定义了验证码,如果我添加以下行:url(r'^captcha/', include('captcha.urls')),
在我的 urls.py 文件中,错误仍然存在。
这是我的 web/views.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python imports
import datetime
import json
# Django imports
from django.shortcuts import render, get_object_or_404
from django.views.generic import View, ListView, DetailView, YearArchiveView, \
MonthArchiveView, TemplateView, FormView
from django.http import Http404, HttpResponse
from django.template import loader, Context
from django.core.mail import EmailMultiAlternatives
from django.db.models import Q
from django.conf import settings
# Captcha imports
from captcha.models import CaptchaStore # This is the line where error occurs
from captcha.helpers import captcha_image_url
# APP imports.
from web.models import Slider, Woman, Article, CategoryArticle, CategoryWoman, \
CategoryBlog, Blog, Banner
from web.constans import MONTHS
from web.utils import women_dates_list
from web.forms import ContactForm, RegisterForm, ContactModelForm
对不起我的英语。
更新 2
Django-Ckeditor 出错
Unhandled exception in thread started by <function wrapper at 0x7fe211911140>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/project/urls.py", line 10, in <module>
url(r'', include('web.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/web/urls.py", line 83, in <module>
(r'^ckeditor/', include('ckeditor.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named urls
这是我的 web/urls.py
# Django imports
from django.conf.urls import patterns, include, url
from django.conf import settings
# App imports
from web import views, models
# URLs
urlpatterns = patterns('',
##
## URLS of the Website
##
# CAPTCHA
url(r'^captcha/', include('captcha.urls')),
# CKEDITOR
(r'^ckeditor/', include('ckeditor.urls')),
)
可能您安装的验证码不是您需要的。 pip install captcha
安装 this. And it has no models. It seems that you need django-simple-captcha。通过运行 pip install django-simple-captcha
.
安装它
更新
将(r'^ckeditor/', include('ckeditor.urls')),
更改为(r'^ckeditor/', include('ckeditor_uploader.urls')),
当我 运行 Django App 我得到以下错误:
Unhandled exception in thread started by <function wrapper at 0x7f8449a387d0>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/project/urls.py", line 10, in <module>
url(r'', include('web.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/web/urls.py", line 6, in <module>
from web import views, models
File "/root/soho-website/backend/web/views.py", line 19, in <module>
from captcha.models import CaptchaStore
ImportError: No module named models
但是,如果我在我的 urls.py 文件中注释以下行:url(r'', include('web.urls')),
我在其中定义了我的索引页面,我的应用程序可以正常工作。
我已经通过 Pip(验证码、Ckeditor、MySQL 等)正确安装了我的所有应用程序
详情:
- 我的项目名称:项目
- Django 版本:1.9.5
- Python 版本:2.7.6 [GCC 4.8.2] on linux2
urls.py 文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
# Website URLs
url(r'', include('web.urls')),
# Admin URLs
url(r'^admin/', include(admin.site.urls)),
)
base.py 文件(部分配置):
import os
from django.core.urlresolvers import set_urlconf
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ROOT_URLCONF = 'project.urls'
WSGI_APPLICATION = 'project.wsgi.application'
DOMAIN_URL = "http://MY_IP"
我的应用程序的结构是:
我的配置有什么问题?
更新
我已经使用 PIP INSTALL 正确安装了验证码。在我的 Installed_APPS 中,我定义了验证码,如果我添加以下行:url(r'^captcha/', include('captcha.urls')),
在我的 urls.py 文件中,错误仍然存在。
这是我的 web/views.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python imports
import datetime
import json
# Django imports
from django.shortcuts import render, get_object_or_404
from django.views.generic import View, ListView, DetailView, YearArchiveView, \
MonthArchiveView, TemplateView, FormView
from django.http import Http404, HttpResponse
from django.template import loader, Context
from django.core.mail import EmailMultiAlternatives
from django.db.models import Q
from django.conf import settings
# Captcha imports
from captcha.models import CaptchaStore # This is the line where error occurs
from captcha.helpers import captcha_image_url
# APP imports.
from web.models import Slider, Woman, Article, CategoryArticle, CategoryWoman, \
CategoryBlog, Blog, Banner
from web.constans import MONTHS
from web.utils import women_dates_list
from web.forms import ContactForm, RegisterForm, ContactModelForm
对不起我的英语。
更新 2
Django-Ckeditor 出错
Unhandled exception in thread started by <function wrapper at 0x7fe211911140>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/project/urls.py", line 10, in <module>
url(r'', include('web.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/soho-website/backend/web/urls.py", line 83, in <module>
(r'^ckeditor/', include('ckeditor.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named urls
这是我的 web/urls.py
# Django imports
from django.conf.urls import patterns, include, url
from django.conf import settings
# App imports
from web import views, models
# URLs
urlpatterns = patterns('',
##
## URLS of the Website
##
# CAPTCHA
url(r'^captcha/', include('captcha.urls')),
# CKEDITOR
(r'^ckeditor/', include('ckeditor.urls')),
)
可能您安装的验证码不是您需要的。 pip install captcha
安装 this. And it has no models. It seems that you need django-simple-captcha。通过运行 pip install django-simple-captcha
.
更新
将(r'^ckeditor/', include('ckeditor.urls')),
更改为(r'^ckeditor/', include('ckeditor_uploader.urls')),