gpt4 book ai didi

django - Django 表单的 ViewDoesNotExist/导入错误

转载 作者:行者123 更新时间:2023-12-04 05:34:57 24 4
gpt4 key购买 nike

当我添加一个表单来添加电话号码时,一切正常。

但是,当我为 full_name 添加字段时,出现此错误:

ViewDoesNotExist at /phone/ Could not import accounts.views.add_phone. View does not exist in module accounts.views..

这是代码:

View .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))

电话表单.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)),

)

最佳答案

您肯定拼错了表单字段类型。最常见的是大写错误。

不过,Django 应该更准确地报告这一点。

关于django - Django 表单的 ViewDoesNotExist/导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12087583/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com