ImportError at /
cannot import name views
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7
Exception Type: ImportError
Exception Value:
cannot import name views
Exception Location: /Users/adam/Desktop/qblog/qblog/urls.py in <module>, line 1
Python Executable: /Users/adam/Desktop/venv/bin/python
Python Version: 2.7.8
Python Path:
['/Users/adam/Desktop/qblog',
'/Users/adam/Desktop/venv/lib/python27.zip',
'/Users/adam/Desktop/venv/lib/python2.7',
'/Users/adam/Desktop/venv/lib/python2.7/plat-darwin',
'/Users/adam/Desktop/venv/lib/python2.7/plat-mac',
'/Users/adam/Desktop/venv/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/adam/Desktop/venv/lib/python2.7/lib-tk',
'/Users/adam/Desktop/venv/lib/python2.7/lib-old',
'/Users/adam/Desktop/venv/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/adam/Desktop/venv/lib/python2.7/site-packages']
Server time: Sun, 21 Sep 2014 15:12:22 +0000
这是urls.py位于qblog / qblog /:
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^markdown/', include('django_markdown.urls')),
url(r'^', include('blog.urls')),
)
另外,如果我添加&#34;库&#34;对于第一个导入语句(我不需要),它会给我相同的错误,但是对于库,&#34;无法导入名称库&#34;。
这是urls.py位于qblog / blog /:
from django.conf.urls import patterns, include, url
from . import views
urlpatterns = patterns(
'',
url(r'^$', views.BlogIndex.as_view(), name="index"),
)
转到网址http://127.0.0.1:8000/index
会出现同样的错误。
运行./manage.py runserver
项目结构:
.
├── blog
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── admin.py
│ ├── admin.pyc
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0001_initial.pyc
│ │ ├── 0002_auto_20140921_1414.py
│ │ ├── 0002_auto_20140921_1414.pyc
│ │ ├── 0003_auto_20140921_1501.py
│ │ ├── 0003_auto_20140921_1501.pyc
│ │ ├── __init__.py
│ │ └── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├── db.sqlite3
├── manage.py
├── qblog
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── static
│ ├── css
│ │ ├── blog.css
│ │ └── bootstrap.min.css
│ ├── icons
│ │ └── favicon.ico
│ └── js
│ ├── bootstrap.min.js
│ └── docs.min.js
└── templates
├── base.html
├── home.html
└── post.html
答案 0 :(得分:11)
无需在项目级文件中导入视图。你没有在那里使用它们,所以没有理由导入它们。
如果您需要,则只需from blog import views
,因为视图位于博客目录中,manage.py将顶级目录放入Python路径。< / p>
答案 1 :(得分:1)
您可以使用import views
。这对我有用