请温柔 - 这是我用Python和Django的第一次Django的设置导入错误
我觉得这是非常一切第一次的经验,但请让我知道,如果有什么事我可以提供。
我得到这个错误:
ImportError at/
No module named models
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.5.1
Exception Type: ImportError
Exception Value:
No module named models
Exception Location: /Users/drewwyatt/Sites/Python/FirstBlog/FirstBlog/blog/views.py in <module>, line 3
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.4
Python Path:
['/Users/drewwyatt/Sites/Python/FirstBlog',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.4-py2.7-macosx-10.6-intel.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Fri, 26 Apr 2013 16:22:15 -0500
和代码...
/FirstBlog/FirstBlog/blog/views.py
from django.shortcuts import render_to_response
from blog.models import posts
def home(request):
return render_to_response('index.html')
/FirstBlog /FirstBlog/blog/models.py
from django.db import models
# Create your models here.
class posts(models.Model):
author = models.CharField(max_length = 30)
title = models.CharField(max_length = 100)
bodytext = models.TextField()
timestamp = models.DateTimeField()
/FirstBlog/FirstBlog/settings.py(线110-115)
TEMPLATE_DIRS = (
"blog/templates",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
/FirstBlog/FirstBlog/urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'FirstBlog.blog.views.home', name='home'),
# url(r'^FirstBlog/', include('FirstBlog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
@NCao完全工作 - 如果你想 “答案” 的问题,我将你标记为公认。 – drewwyatt 2013-04-26 21:44:05
你可以发布'/ FirstBlog/FirstBlog/blog/__ init __。py'的内容吗? – phihag 2013-04-26 21:46:22