Django模板没有加载任何东西(空白屏幕)

时间:2016-01-20 11:57:51

标签: python django model-view-controller web

已经解决了,我真的很抱歉这是一个初学者的错误...问题出在我的_layouts / base.html中,它没有渲染,因为它错过了HTML在< !DOCTYPE>

您可以在pastebin链接中查看_layout / base.html

我抓了整个互联网,仍然无法在这里找到我做错的代码: Views.py:

from django.shortcuts import render
from django.views import generic
from django.views.generic import TemplateView   
from django.http import HttpResponse
# Create your views here.

def home_page(request):
    return HttpResponse('hello')

class HomePageView(generic.TemplateView):
    template_name = 'home.html'

class HomePageView2(TemplateView):
    template_name = 'home.html'

urls.py:

from django.conf.urls import url
from django.contrib import admin
from app1.views import *
#from django.shortcuts import render
from django.views.generic import TemplateView

urlpatterns = [
    url(r'^$',HomePageView.as_view(), name = 'home.html'),
    url(r'^1/$',HomePageView2.as_view(template_name="home.html")),
    url(r'^admin/', admin.site.urls),
    url(r'^nn/$', home_page )
]

home.html的:



{% extends '_layouts/base.html' %}

{% block headline %}<h1>Welcome to the PyCon Survival Guide</h1>{% endblock  %}

{% block content %}
<p>Howdy {% if user.is_authenticated %} {{ user.username }}{% endif %} </p>
{% endblock %}
&#13;
&#13;
&#13;

my _layouts / base.html: http://pastebin.com/LVHbduqm

HomePageView HomePageView2 都不会渲染我的模板!

settings.py和我的文件夹树: settings.py and my folder tree

P.S。 : Example of blank screen

2 个答案:

答案 0 :(得分:2)

我知道这可能看起来很愚蠢,但你的home.html是什么样的?

如果你要回200,但没有渲染,那么你的home.html可能是空白的吗?

答案 1 :(得分:0)

这与您正在使用的方法略有不同,但

<强> views.py

class HomePageView(generic.TemplateView):
    template_name = 'home.html'

变为

def home_page_view(request):
    return render(request, 'home.html')

urls.py

url(r'^$',HomePageView.as_view(), name = 'home.html'),

变为

url(r'^$', home_page_view, name = 'home'),