我在尝试创建一个将电子邮件保存到数据库中的简单页面时收到此错误。任何帮助将非常感激!谢谢!
这是我的models.py:
from django import forms
from django import models
class Tester(models.Model):
email = models.TextField()
class TesterForm(ModelForm):
class Meta:
model = Tester
fields = ['testeremail']
和我的views.py:
from django.http import HttpResponseRedirect
from community.models import Tester
def savetester(request):
if request.method == 'POST':
testeremail = request.POST.get('testeremail', '')
tester_obj = Tester(email=testermail)
tester_obj.save()
return HttpResponseRedirect('/board/')
我的urls.py:
(r'^test/$', TemplateView.as_view(template_name = "test.html")),
(r'^savetester/$', 'community.views.savetester'),
现在我的test.html:
<form action="/savetester/" method="post" accept-charset="utf-8">{% csrf_token %}
<label for="testeremail">E-Mail:</label><input type="text" name="testeremail" value="" id="testeremail" />
<p><input type="submit" value="Add"></p>
</form>
这是追溯:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/savetester/
Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.humanize',
'django.contrib.flatpages',
'django.contrib.admin',
'django.contrib.sitemaps',
'sphene.community',
'sphene.sphboard',
'sphene.sphwiki',
'sphene.sphblog']
Installed Middleware:
('sphene.community.middleware.ThreadLocals',
'sphene.community.middleware.GroupMiddleware',
'sphene.community.middleware.MultiHostMiddleware',
'sphene.community.middleware.LastModified',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.doc.XViewMiddleware',
'sphene.community.middleware.PermissionDeniedMiddleware',
'django.middleware.csrf.CsrfViewMiddleware')
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
158. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in _get_callback
167. raise ViewDoesNotExist("Could not import %s. Error was: %s" % (mod_name, str(e)))
Exception Type: ViewDoesNotExist at /savetester/
Exception Value: Could not import community.views. Error was: cannot import name models
答案 0 :(得分:1)
models
位于django.db
from django.db import models