Python中文
首页
教程
问答
标签
搜索
登录
注册
html表单中不允许Django HTTP 405方法
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我是Django新手,我一直在尝试开发一个简单的网站,询问用户的电子邮件地址和身高。然后它将其保存在数据库中,并向用户发送电子邮件,并将他们重定向到一个页面,说明成功了。在</p> <p>现在的问题是,每当我按“提交”时,都会收到一个http405方法不允许的错误。在</p> <pre><code># urls.py urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), #url(r'^success/$', views.SuccessView.as_view(), name='success'), ] </code></pre> <p><br/> # 表单.py 班级高度表(窗体.ModelForm)公司名称:</p> ^{pr2}$ <p><br/></p> <pre><code># views.py class IndexView(generic.ListView): form_class = HeightForm template_name = 'heights/index.html' def get_queryset(self): return Height.objects.all() class HeightFormView(View): form_class = HeightForm template_name = 'heights/success.html' def get(self, request): form = form_class(None) def post(self, request): print('a' * 1000) form = form_class(request.POST) if form.is_valid: email = form.cleaned_data['email'] height = form.cleaned_data['height'] form.save() return HttpResponseRedirect(template_name) #render(request, template_name, {'form': form}) </code></pre> <p><br/></p> <pre><code># index.html {% extends 'heights/base.html' %} {% block body %} <h1>Collecting Heights</h1> <h3>Please fill the entries to get population statistics on height</h3> <form action="" method="post"> {% csrf_token %} <input type="email" name="email" placeholder="Enter your email address" required="true"/><br /> <input type="number" min="50" max="300" name="height" placeholder="Enter your height in cm" required="true" /><br /><br /> <input type="submit" name="submit" /> </form> <a href="#">Click to view all heights in database</a> {% endblock body %} </code></pre> <p>代码甚至不能到达<code>print('a' * 1000)</code>行而不生成错误。Chrome只是转到<code>This page isn't working</code>页面并显示<code>HTTP ERROR 405</code>。在</p> <p>我在google上搜索了这个错误,但没有发现anthing有用。感谢任何帮助</p> <p>谢谢</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您似乎没有为HeightFormView定义任何URL。表单由IndexView呈现并返回给它自己;该视图不允许使用POST方法。在</p> <p>您需要为HeightFormView定义一个URL,并通过<code>{% url %}</code>标记在操作中引用它。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
6 回答
将Pandas数据帧转换为scipy稀疏矩阵
6 回答
将Pandas数据帧转换为Spark Datafram时出现问题
10 回答
将pandas数据帧转换为spark DataFram时出错
1 回答
将Pandas数据帧转换为spark datafram时收到错误
10 回答
将Pandas数据帧转换为Spark数据帧
4 回答
将Pandas数据帧转换为Tensorflow数据
10 回答
将Pandas数据帧转换为tkinter obj
1 回答
将pandas数据帧转换为XML
5 回答
将Pandas数据帧转换为值sql语句
5 回答
将pandas数据帧转换为元组
7 回答
将pandas数据帧转换为元组列表
10 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
9 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
8 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
3 回答
将pandas数据帧转换为内存中类似文件的对象?
6 回答
将Pandas数据帧转换为内存功能(&F)
1 回答
将pandas数据帧转换为列表列表
2 回答
将pandas数据帧转换为列表列表以输入到RNN
4 回答
将Pandas数据帧转换为单行DataFram
1 回答