当我添加一个表格来添加电话号码时,一切正常。
但是,当我为 full_name 添加字段时,出现此错误:
ViewDoesNotExist at /phone/ Could not import accounts.views.add_phone. View does not exist in module accounts.views..
这是代码:
视图.py
class PhoneForm(forms.Form):
phone = forms.IntegerField()
full_name = forms.Charfield()
def add_phone(request):
if request.method == 'POST':
form = phone_name_form(request.POST)
if form.is_valid():
phone = form.cleaned_data['phone']
#fullname = form.cleaned_data['fullname']
user = request.user
#store phone number to user profile
user.get_profile().phone = phone
user.get_profile().save()
#store fullname in the "firstname" field for User
# print "fullname"
#print fullname
return HttpResponseRedirect("/menu/")
else:
form = phone_name_form() #an unbound form
return render_to_response("phone_form.html", {'form' : form}, context_instance=RequestContext(request))
phone_form.html
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
网址.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^signup/$', 'accounts.views.signup'),
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^phone/$', 'accounts.views.add_phone'),
url(r'^users/', 'accounts.views.register_complete'),
url(r'^$', 'food.views.menu'),
url(r'^menu/$', 'food.views.menu'),
url(r'^menu/(?P<hour>\d+)/$', 'food.views.menu_hour'),
url(r'^menu/(?P<hour>\d+)/(?P<food>\w+)/$', 'cart.views.add_to_cart_view'),
url(r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
url(r'^cart/', include('cart.urls')),
url(r'^checkout/', 'cart.views.checkout'),
#url(r'^menu/12/$', 'food.views.menu_hour'),
# Examples:
# url(r'^$', 'foodchute.views.home', name='home'),
# url(r'^foodchute/', include('foodchute.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)),
)