编辑1:
我正在用 django 构建一个博客,最近我向模板文件夹添加了一些 html/css 文件,但它没有加载。
这些是我的 html 代码
基地.html:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link href="{% static "css/blog.css" %}" rel="stylesheet">
</head>
<body>
<div id="content">
{% block content %}
{% endblock %}
</div>
<div id="sidebar">
<h2>My blog</h2>
<p>This is my blog.</p>
</div>
</body>
</html>
列表.html
> {% extends "blog/base.html" %} {% block title %}My Blog{% endblock
> %} {% block content %} <h1>My Blog</h1> {% for post in posts %}
> <h2>
> <a href="{{ post.get_absolute_url }}">
> {{ post.title }}
> </a>
> </h2>
> <p class="date">
> Published {{ post.publish }} by {{ post.author }}
> </p>
> {{ post.body|truncatewords:30|linebreaks }} {% endfor %} {% endblock %}
我可能是错的,但我认为问题可能来自下面的视图和网址
视图.py
> from django.shortcuts import render, get_object_or_404 from .models
> import Post
>
> def post_list(request): posts = Post.published.all() return
> render(request,
> 'blog/post/list.html',
> {'posts': posts})
>
> def post_detail(request, year, month, day, post): post =
> get_object_or_404(Post, slug=post,
> status='published',
> publish__year=year,
> publish__month=month,
> publish__day=day) return render(request,
> 'templates/blog/post/detail.html',
> {'post': post})
网址.py
> from django.urls import path from . import views
>
> app_name = 'blog'
>
> urlpatterns = [ # post views path('', views.post_list,
> name='post_list'),
> path('<int:year>/<int:month>/<int:day>/<slug:post>/',
> views.post_detail, name='post_detail'), ]
动漫人物
慕少森
相关分类