Lau*_*ent 9 python django rest django-rest-framework
我正在使用django rest框架,如下所述:django rest framework doc我在我的模板目录中添加了/rest_framework/api.html.
现在的结构是:
|
|\
| apps
| \
| settings.py
\
templates
\
rest_framework
\
api.html
Run Code Online (Sandbox Code Playgroud)
api.html:
{% extends "rest_framework/base.html" %}
{% block footer %}
Hello !
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
settings.py:
...
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)),
)
Run Code Online (Sandbox Code Playgroud)
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.markup',
'django.contrib.webdesign',
...
'rest_framework',
...
)
Run Code Online (Sandbox Code Playgroud)
...
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'PAGINATE_BY': 10
}
Run Code Online (Sandbox Code Playgroud)
我在api.html中进行的修改不会显示在可浏览的api中.我究竟做错了什么 ?
小智 9
你是否缺少主要settings.py中的DIRS(这告诉我们在哪里寻找模板(覆盖模板):
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
...
}
Run Code Online (Sandbox Code Playgroud)
您使用的是哪个版本的 Django REST Framework?我对 base.html 中的块页脚进行了更改,这是为 3.0 版本计划的。
是你的“你好!” 也没有显示在页面的源代码中(您可以通过按 CTRL+U 获取它)?
如果是,那么最终可能是 CSS 将颜色设置为白色的问题。您可以输入“您好!” 在这样的标签中:<p>Hello !</p>.
编辑:
附加信息。
粘性页脚始终显示在页面底部下方 60 像素处,因此存在问题,因此需要向下滚动才能看到它。如果您使用的是旧版本,这也可能会导致问题。最重要的问题是:“你好!” 发送到浏览器的 HTML 源代码中根本不存在,或者它确实存在,但您在页面上看不到它?
请给我反馈,以便我们解决这个问题。
| 归档时间: |
|
| 查看次数: |
4435 次 |
| 最近记录: |