2

優しくしてください - これは Python と 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)),
)
4

2 に答える 2

1

django エラーは非常に便利です。

Exception Location: /Users/drewwyatt/Sites/Python/FirstBlog/FirstBlog/blog/views.py in <module>, line 3

試す:

FirstBlog/FirstBlog/ブログ/views.py

from django.shortcuts import render_to_response

from FirstBlog.blog.models import posts  

def home(request):
    return render_to_response('index.html')
于 2013-04-26T21:52:46.417 に答える