编辑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'), ]
3 回答
动漫人物
TA贡献1815条经验 获得超10个赞
在你的 base.html
改变这一行
<link href="{% static "css/blog.css" %}" rel="stylesheet">
到
<link href="{% static 'css/blog.css' %}" rel="stylesheet">
慕少森
TA贡献2019条经验 获得超9个赞
class MyModelAdmin(admin.ModelAdmin):
class Media:
js = ('js/admin/my_own_admin.js',)
css = {
'all': ('css/admin/my_own_admin.css',)
}
添加回答
举报
0/150
提交
取消