简体   繁体   English

Django:没有CSS和正确文字的html

[英]Django: html without CSS and the right text

First of all, this website that I'm trying to build is my first, so take it easy. 首先,我要建立的这个网站是我的第一个网站,所以请放轻松。 Thanks. 谢谢。 Anyway, I have my home page, home.html , that extends from base.html , and joke.html , that also extends base.html . 无论如何,我有主页home.html (从base.html扩展)和joke.html (也从base.html扩展)。 The home page works just fine, but not the joke page. 主页工作正常,但笑话页面却不行。 Here are some parts of my files, for you to understand how I want my system to work: 这是文件的某些部分,以供您了解我希望系统如何工作:

views.py views.py

def joke_page(request, joke_id):
    joke = Joke.objects.get(id=int(joke_id))
    return render(request, 'joke.html', {'joke': joke})

urls.py urls.py

urlpatterns = [
    url(r'^$', views.home_page, name='home_page'),
    url(r'^(?P<joke_id>[0-9]+)/$', views.joke_page, name='joke_page'),
]  

joke.html joke.html

{% extends 'base.html' %}

{% block header_text %}{{ joke.title }}{% endblock %}

{% block text %}{{ joke.text }}{% endblock %}

What I want is that URLs that end like jokes/1/ to render a page with the right html using joke.html. 我想要的是以jokes / 1 /结尾的URL,以便使用joke.html用正确的html呈现页面。 Instead, it renders a page without CSS or with joke.title and joke.text Also, I noticed that jokes/1/ doesn't find anything: 相反,它呈现的页面没有CSS或joke.title和joke.text。此外,我注意到jokes / 1 /找不到任何内容:

DoesNotExist at /jokes/1/

Joke matching query does not exist.. 

I had 20 jokes in the database and I can find jokes/2/ through jokes/21/, which means their ids have shifted? 我在数据库中有20个笑话,并且可以通过jokes / 21 /找到笑话/ 2 /,这意味着它们的ID已经改变了? :P Can someone experienced with Django point out my(many, without a doubt) mistakes? :P有经验的Django可以指出我的(很多,毫无疑问)错误吗? Thank you! 谢谢!

Edit: second urls.py 编辑:第二个urls.py

urlpatterns = [
    url(r'^$', jokes_views.home_page, name='home'),
    url(r'^jokes/', include(jokes_urls)),
    url(r'^admin/', include(admin.site.urls)),
]

您是否在模板中使用{%load staticfiles%}?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM