Django 1.7 - 更新base_site.html不工作 [英] Django 1.7 - updating base_site.html not working

查看:110
本文介绍了Django 1.7 - 更新base_site.html不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注django 1.7的教程(再次)。我无法让管理员网站更新。我遵循了这一点:

I'm following the tutorial for django 1.7 (again). I cannot get the admin site to update. I've followed this:

Django :覆盖base_site.html

this:

在Django中自定义base_site.html不工作

和一些非现场的东西链接。

and a couple of offsite things links.

我的设置文件如下所示:

My settings file looks like this:

""" 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/'

我知道我的文件结构正在运行如果我把所有东西都砍掉了o f base_site.html,并将其替换为当我访问管理站点时显示的wtf。我已经从django安装中删除了admin / base_site.html,但仍然得到'Django管理'。

And I know my file structure is working because if I cut everything out of the base_site.html and replace it with 'wtf' that's exactly what displays when I visit the admin site. I've gone as far as to delete the admin/base_site.html from the django install but still I get the 'Django administration'.

当不说'wtf'我的base_site.html如下所示:

When it doesn't say 'wtf' my base_site.html looks like this:

{% 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 %}

我想这应该是1.7,因为我在1.6中工作,但我检查了1.6,1.7和dev的文档,找不到什么问题。

I guess this must be something to do with 1.7 as I got it working in 1.6 but I've checked the docs for 1.6, 1.7 and dev and can't find what's wrong.

我正在开发一个运行本地MySQL数据库的虚拟环境中的Windows。

I'm developing on windows in a virtual env running a local MySQL db.

推荐答案

要开始,我不知道这是否是一个复制/粘贴问题,或者您实际上已经注释了TEMPLATE_DIRS。它将需要是一个非注释行:

To start off, I am not sure if it was a copy/paste issue or if you actually have TEMPLATE_DIRS commented out. It will need to be a non-commented line:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

对于真正的问题,您必须更换更多的模板才能使其工作,因为site_title在这里定义: https://github.com/django/django/ blob / 1.7 / django / contrib / admin / sites.py#L36
和site_header在此定义: https://github.com/django/django/blob/1.7/django/contrib/admin/sites.py#L39

As for the real problem, you have to replace more of your template to make it work because site_title is defined here: https://github.com/django/django/blob/1.7/django/contrib/admin/sites.py#L36 and site_header is defined here: https://github.com/django/django/blob/1.7/django/contrib/admin/sites.py#L39

默认值仅在这些不存在的情况下才起作用,因此您的模板应如下所示:

Default will only work if these do not exist, so your template should look like this:

{% 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 %}

您可以在这里了解有关默认标签的更多信息: https: //docs.djangoproject.com/en/1.7/ref/templates/builtins/#default

You can learn more about the default tag here: https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#default

这篇关于Django 1.7 - 更新base_site.html不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆