Python Django 1.7-更新base_site.html不起作用
我将继续学习django 1.7的教程(再次)。我无法获取要更新的管理站点。我注意到: 这: 还有一些场外链接 我的设置文件如下所示:Python Django 1.7-更新base_site.html不起作用,python,django,django-templates,django-admin,Python,Django,Django Templates,Django Admin,我将继续学习django 1.7的教程(再次)。我无法获取要更新的管理站点。我注意到: 这: 还有一些场外链接 我的设置文件如下所示: """ Django settings for website project. For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/ For the full list of settings and their val
""" Django settings for website project.
For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True
TEMPLATE_DEBUG = True
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', 'blog',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', )
ROOT_URLCONF = 'website.urls'
WSGI_APPLICATION = 'website.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '', 'USER': 'root', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '3306',
} }
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'GMT'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('whatever site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('whatever site administration') }}</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% extends "admin/base.html" %}
{% block title %}{{ title }} | whatever site admin{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">whatever site administration</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
我知道我的文件结构在工作,因为如果我把base_site.html中的所有内容都删掉,并用“wtf”替换,这正是我访问管理站点时显示的内容。我甚至从django安装中删除了admin/base_site.html,但仍然得到了“django管理”
当它没有说“wtf”时,my base_site.html如下所示:
""" Django settings for website project.
For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True
TEMPLATE_DEBUG = True
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', 'blog',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', )
ROOT_URLCONF = 'website.urls'
WSGI_APPLICATION = 'website.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '', 'USER': 'root', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '3306',
} }
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'GMT'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('whatever site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('whatever site administration') }}</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% extends "admin/base.html" %}
{% block title %}{{ title }} | whatever site admin{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">whatever site administration</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{%extends“admin/base.html”%}
{%block title%}{{title}}{{site_title}默认值:{('which site admin')}{%endblock%}
{%block-branding%}
{%endblock%}
{%block nav global%}{%endblock%}
我想这一定与1.7有关,因为我在1.6中使用了1.7,但我检查了1.6、1.7和dev的文档,没有发现什么问题
我正在windows上开发一个运行本地MySQL数据库的虚拟环境。首先,我不确定这是一个复制/粘贴问题,还是您实际上已经注释掉了模板目录。它需要是一个非注释行:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
至于真正的问题,您必须替换更多模板才能使其正常工作,因为此处定义了站点标题:
此处定义了站点_标题:
默认设置仅在这些设置不存在时有效,因此您的模板应如下所示:
""" Django settings for website project.
For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True
TEMPLATE_DEBUG = True
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', 'blog',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', )
ROOT_URLCONF = 'website.urls'
WSGI_APPLICATION = 'website.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '', 'USER': 'root', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '3306',
} }
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'GMT'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('whatever site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('whatever site administration') }}</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% extends "admin/base.html" %}
{% block title %}{{ title }} | whatever site admin{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">whatever site administration</a></h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{%extends“admin/base.html”%}
{%block title%}{{title}}|任何站点管理员{%endblock%}
{%block-branding%}
{%endblock%}
{%block nav global%}{%endblock%}
您可以在此处了解有关默认标记的更多信息:顺便说一句,django 1.6中不存在site_title和site_header,这就是您以前的标签工作的原因。谢谢Zach。这是模板目录上的复制粘贴问题。非常感谢,你的建议奏效了。我将仔细阅读默认标记。只是为了澄清重新教程的建议:
{%block title%}{{{title}}{{{{{{('Polls administration')}{%endblock%}
和