python - 数组中的 Django 项目不显示
问题描述
我的 Django 项目(再次)有问题。我正在尝试制作一个添加文章然后将所有文章显示为列表的功能。发生的事情是它只是不显示它,我不知道为什么。
视图.py:
from django.shortcuts import render
from django.http import HttpResponse
from . import util
import random
def index(request):
entries = util.list_entries()
random_page = random.choice(entries)
return render(request, "encyclopedia/index.html", {
"entries": util.list_entries(),
"random_page": random_page,
})
def CSS(request):
return render(request, "encyclopedia/css_tem.html", {
"article_css": "css is slug and cat"
})
def Python(request):
return render(request, "encyclopedia/python_tem.html", {
"article_python": "python says repost if scav"
})
def HTML(request):
return render(request, "encyclopedia/HTML_tem.html", {
"article_HTML": "game theory: scavs are future humans"
})
def Git(request):
return render(request, "encyclopedia/Git_tem.html", {
"article_Git": "github is git"
})
def Django(request):
return render(request, "encyclopedia/Django_tem.html", {
"article_Django": "this is a framework"
})
def new_article(request):
created_articles = ["lol","pls"]
return render(request, "encyclopedia/new_article_tem.html", {
"article_Django": "this is a framework"
})
new_article(在这里我可以输入我想在文章中出现的内容):
{% extends "encyclopedia/layout.html" %}
{% block title %}
New Article
{% endblock %}
{% block body %}
<h1>Create Article</h1>
<form action = "http://127.0.0.1:8000">
<textarea class="new_article_title_css" type="text" name="new_article_title" placeholder="This will be the title of your article!"></textarea>
<p></p>
<textarea class="new_article_text_css" type="text" name="new_article_text" placeholder="Write your article here!"></textarea>
<p></p>
<input class = "submit_new_article" type = "submit" value="create">
</form>
{% endblock %}
指数:
{% extends "encyclopedia/layout.html" %}
{% block title %}
Encyclopedia
{% endblock %}
{% block body %}
<h1>All Pages</h1>
<ul>
{% for entry in entries %}
<li><a href = /{{entry}}>{{ entry }}</a></li>
{% endfor %}
{% for article_title in created_articles %}
<li>{{article_title}}</li>
{% endfor %}
</ul>
{% endblock %}
解决方案
推荐阅读
- html - 您如何将 img 放置在 HTML 和 css 中的 div 上方
- algorithm - 将矩形放置在多边形内的算法
- javascript - Ruby on Rails 表单添加带有文本框的“其他”选项以选择下拉菜单
- nginx - 安全链接模块 NGINX 中的文件名
- html - 当我切换到按月/按年计费时,我得到“NaN”作为文本内容。否则,我的 JS 代码运行良好。我的代码片段附在下面
- python - 更新 Discord 中已存在的嵌入消息
- reactjs - 如果没有找到值,如何返回对象,否则使用条件循环并使用反应和打字稿返回对象?
- ios - Swift - 使用 snapkit 的滚动视图中的 pageviewcontroller 表视图
- sql-server - 使用 SSIS 包将带有嵌套节点的 XML 导入 SQL Server 数据库,并将文件中的记录 ID 添加到每个插入
- javascript - 当名称和值位于不同的 XML 节点中时,使用 Javascript 从 XML 中的某些节点解析属性?