我想自定义 Django REST Framework 可浏览 API 模板(只需将品牌更改为不同的名称和链接)。
我已阅读有关如何实现此目标的文档,并最初在以下路径中执行了以下操作:hints(project)->hints1(app)->templates->rest_framework->api.html
api.html:
{% extends "rest_framework/base.html" %}
{% block title %} Handy Dev Hints - API {% endblock %}
{% block branding %}
<span>
<a class='navbar-brand' rel="nofollow" href="{% url 'html' %}">
-----HTML View----- <span class="version">1</span>
</a>
</span>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
我还修改了我的settings.py,如下所示,特别是 DIRS 部分:
设置.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR, 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',
],
},
},
]
Run Code Online (Sandbox Code Playgroud)
从我看过的教程和我读过的文档来看,这应该足以实现更改。然而,这并没有奏效。
所以我决定直接在 site-packages 库中更改 base.html 。 …
这是一个 Django 项目。pip install -r requirements.txt在本地 virtualenv 中运行时遇到错误。
Collecting https://github.com/jedestep/Zappa/archive/layer-support.zip (from -r requirements\base.txt (line 9))
Using cached https://github.com/jedestep/Zappa/archive/layer-support.zip
ERROR: Command errored out with exit status 1:
command: 'c:\users\user~1\desktop\project\project\venv\scripts\python.exe' -c 'import sys, setuptools, tokenize
; sys.argv[0] = '"'"'C:\\Users\\USER~1\\AppData\\Local\\Temp\\pip-req-build-6htw2gh2\\setup.py'"'"'; __file__='"'"'C:\
\Users\\USER~1\\AppData\\Local\\Temp\\pip-req-build-6htw2gh2\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(
__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' e
gg_info --egg-base 'C:\Users\USER~1\AppData\Local\Temp\pip-req-build-6htw2gh2\pip-egg-info'
cwd: C:\Users\USER~1\AppData\Local\Temp\pip-req-build-6htw2gh2\
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\USER~1\AppData\Local\Temp\pip-req-build-6htw2gh2\setup.py", line 8, in <module>
long_description = readme_file.read()
File "c:\users\user~1\desktop\project\project\venv\lib\encodings\cp1252.py", line …Run Code Online (Sandbox Code Playgroud)