请帮助。我正在遵循以下django速成课程: https://ceiphr.com/blog/a-crash-course-in-django 但最后一节标题为“带有样式的模板”之后,我得到了空白页。我正在使用Django 2.2.0。
命令树返回的内容。
.
├── blog
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── db.sqlite3
├── django_cc
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
├── manage.py
├── Pipfile
├── Pipfile.lock
└── templates
└── index.html
我的settings.py文件如下:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
这是index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Posts | Django Crash Course</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css"
crossorigin="anonymous"/>
</head>
<body>
<div class="container">
{% for post in posts %}
<div class="card">
<div class="card-image">
<figure class="image">
<img src="{{ post.image.url }}" alt="Placeholder image"
style="max-width: 250px; max-height: 250px;">
</figure>
</div>
<div class="card-content">
<div class="content">
<b>{{ post.title }}</b> | {{ post.description }}
<br>
<time datetime="{{ post.date }}">{{ post.date }}</time>
</div>
</div>
</div>
{% endfor %}
</div>
</body>
</html>
views.py
from django.shortcuts import render
from django.views.generic.base import View
from django.views.generic import TemplateView
from blog.models import Post
class PostFeed(TemplateView):
template_name = 'index.html'
def get_context_data(self, *args, **kwargs):
context = super(PostFeed, self).get_context_data(**kwargs)
context["posts"] = Post.objects.all()
return context
models.py
from django.db import models
# Create your models here.
import datetime
class Post(models.Model):
image = models.FileField(upload_to='images/')
title = models.CharField(default="", max_length=64)
description = models.CharField(default="", max_length=512)
date = models.DateField(default=datetime.date.today)
class Meta:
ordering = ['-date']
def __str__(self):
return self.title
答案 0 :(得分:0)
您需要在#include <stdio.h>
#define IN 1 /*inside a word*/
#define OUT 0 /*outside a word*/
/* count lines, words, and characters in input*/
int main(void)
{
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF){
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT){
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
printf("EOF = %d\n", EOF);
return 0;
}
get_context_data
答案 1 :(得分:0)
如果该项目没有通过Django控制面板创建的任何“发布”条目,则该项目将始终显示空白页面。
您应该在本教程的“编写模型”部分之后填充开发数据库。