首页 > 解决方案 > 数组中的 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 %}

标签: pythonhtmldjango

解决方案


推荐阅读