我变了设置.py如下。在import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mytweets.urls'
STATICFILES_DIRS = [
os.path.join(
os.path.dirname(__file__),
'static',
),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
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',
],
'loaders': (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
),
},
},]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
...
STATIC_URL = '/static/'
我变了视图.py文件如下。在
^{pr2}$
那我就变了网址.py文件如下。在from django.conf.urls import patterns, include, url
from django.contrib import admin
from tweets.views import Index
admin.autodiscover()
urlpatterns = [
url(r'^$', Index.as_view()),
url(r'^admin/', include(admin.site.urls)),
]
我终于做到了基本.html文件。在{% load staticfiles %}
Django{% block content %}
Hello Django!
{% endblock %}
教程说,当我执行$python时管理.py运行服务器,我将看到“Hello Django”,这取决于基本.html。
但我可以看到“我是从get请求调用的”,这取决于视图.py。
我想知道出了什么问题,我该如何渲染基本.html?
谢谢你的时间。在