Python中文
首页
教程
问答
标签
搜索
登录
注册
表单未显示在页面中
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>嘿,伙计们需要一点帮助,我好像想不出来。由于某些原因,我的表单不会显示在我的页面中,请参阅下面的代码</p> <p>forms.py</p> <pre><code>class NewEntryForm(forms.Form): title = forms.CharField(label = "Title") content = forms.CharField(label = "Body") </code></pre> <p>views.py</p> <pre><code>def new(request): if request.method == 'POST': form = NewEntryForm(request.POST) if form.is_valid(): title = form.cleaned_data['title'] content = form.cleaned_data['body'] content = markdown2.markdown(title) filename = f"entries/{title}.md" if default_storage.exists(filename): return render(request, "encyclopedia/error.html", { "error":'A file with this title already exists.' }) else: util.save_entry(title, content) return redirect('entry_page', title=title) else: return render(request, 'encyclopedia/new.html', {'form':NewEntryForm()}) </code></pre> <p>url.py</p> <pre><code>urlpatterns = [ path("", views.index, name="index"), path("wiki/<str:title>", views.entry, name="entry"), path("search/", views.search, name="search"), path("wiki/new", views.new, name="new") ] </code></pre> <p>new.html</p> <pre><code>{% extends "encyclopedia/layout.html" %} {% block title %} Encyclopedia {% endblock %} {% block body %} <form class="" action="" method="post"> {% csrf_token %} {{form}} <input type="submit" name="" value="Submit"> </form> {% endblock %} </code></pre> <p><a href="https://i.stack.imgur.com/1qkRc.png" rel="nofollow noreferrer">Page output</a></p> <p><a href="https://i.stack.imgur.com/lAXbP.png" rel="nofollow noreferrer">cli output</a></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>原来是我的URL.py文件。接受str参数的url正在验证为空白页,因为Django按顺序检查url。我只是将str url移到了urls.py的底部,它成功了</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何格式化凌乱的html源代码?python
10 回答
如何格式化列中的datetime值而不使用pandas中的to\datetime函数?
7 回答
如何格式化列表以将其作为输入提供给支持向量机训练()在opencv3.0中
3 回答
如何格式化列表和字典理解
5 回答
如何格式化刮板输出
6 回答
如何格式化包含不同表达式的原始字符串?
7 回答
如何格式化卷积(1D)keras神经网络的输入和输出形状?Python
5 回答
如何格式化参数的帮助输出?
1 回答
如何格式化双对数x轴刻度标签显示为10的幂?
7 回答
如何格式化可变数量的参数?
9 回答
如何格式化和加载4dr中的数组?
1 回答
如何格式化和合并单个CSV文件中的列
1 回答
如何格式化和打印仪表板到PDF?
6 回答
如何格式化和重写多个文件?
4 回答
如何格式化多变量LSTM(keras)的培训/测试数据,多个观察点和每个观察点的单一结果变量?
3 回答
如何格式化多维数组列表?
6 回答
如何格式化字典(最初来自数据帧)以供操作使用?
1 回答
如何格式化字典列表中的字典对象?
5 回答
如何格式化字符串以创建可编辑列表?
9 回答
如何格式化字符串和字符串一起使用
8 回答