Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Settings.py中的Django 1.8.1模板_Django_Templates - Fatal编程技术网

Settings.py中的Django 1.8.1模板

Settings.py中的Django 1.8.1模板,django,templates,Django,Templates,我已经在这上面呆了一段时间了。我遵循的是1.8,我无法让Django呈现我编辑的模板。相反,它们在Djano libs中呈现默认模板。请参阅官方教程中标题为“自定义管理员外观”的部分(上面的链接) 场地结构 试验场 民意测验 模板 管理员 base_site.html 试验场 设置.py 所有行与教程中的相同。这是他们建议编辑的行(像这样) 其他一切都与教程中的一样。我想我一定是把目录结构弄糊涂了,这就是为什么django无法提取编辑过的模板。我也遇到了同样的问题,结果是我没有替

我已经在这上面呆了一段时间了。我遵循的是1.8,我无法让Django呈现我编辑的模板。相反,它们在Djano libs中呈现默认模板。请参阅官方教程中标题为“自定义管理员外观”的部分(上面的链接)

场地结构
  • 试验场
    • 民意测验
    • 模板
      • 管理员
        • base_site.html
    • 试验场
设置.py 所有行与教程中的相同。这是他们建议编辑的行(像这样)


其他一切都与教程中的一样。我想我一定是把目录结构弄糊涂了,这就是为什么django无法提取编辑过的模板。

我也遇到了同样的问题,结果是我没有替换模板中正确的部分。我通过观察发现了这一点。既然我不是唯一犯这个错误的人,也许你也在犯这个错误:-)

这是base_site.html的原始内容

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}
{%extends“admin/base.html”%}
{%block title%}{{title}}{{site_title}默认值:{('Django site admin')}{%endblock%}
{%block-branding%}
{%endblock%}
{%block nav global%}{%endblock%}
我只是替换字符串“Django administration”,所以它看起来像这样:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Polls Administration') }}</a></h1>
{% endblock %}
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
        __init__.py
        admin.py
        migrations/
            __init__.py
            0001_initial.py
        models.py
        static/
            polls/
                images/
                    background.gif
                style.css
        templates/
            polls/
                detail.html
                index.html
                results.html
        tests.py
        urls.py
        views.py
    templates/
        admin/
            base_site.html
{%extends“admin/base.html”%}
{%block title%}{{title}}{{site_title}默认值:{('Django site admin')}{%endblock%}
{%block-branding%}
{%endblock%}
事实证明,您需要替换

{%endblock%}
{%block nav global%}{%endblock%}

我希望这也能解决您的问题。

我也遇到了同样的问题,结果是我没有替换模板中正确的部分。我通过查看发现了这一点。因为我不是唯一犯此错误的人,也许您也在犯此错误:-)

这是base_site.html的原始内容

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}
{%extends“admin/base.html”%}
{%block title%}{{title}}{{site_title}默认值:{('Django site admin')}{%endblock%}
{%block-branding%}
{%endblock%}
{%block nav global%}{%endblock%}
我只是替换字符串“Django administration”,所以它看起来像这样:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Polls Administration') }}</a></h1>
{% endblock %}
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
        __init__.py
        admin.py
        migrations/
            __init__.py
            0001_initial.py
        models.py
        static/
            polls/
                images/
                    background.gif
                style.css
        templates/
            polls/
                detail.html
                index.html
                results.html
        tests.py
        urls.py
        views.py
    templates/
        admin/
            base_site.html
{%extends“admin/base.html”%}
{%block title%}{{title}}{{site_title}默认值:{('Django site admin')}{%endblock%}
{%block-branding%}
{%endblock%}
事实证明,您需要替换

{%endblock%}
{%block nav global%}{%endblock%}

我希望这也能解决你的问题。

我也有同样的问题。(Django 1.8教程)。 然后,在settings.py中,在BASE_DIR定义之后,我添加了一个print语句

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(BASE_DIR)
在命令行中,我输入:

python manage.py runserver
查看BASE_DIR的值。结果表明,BASE_DIR显示的文件夹比polls高一个文件夹

然后,我在settings.py中更改了模板定义,如下所示:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'polls', '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',
        ],
    },
},
]


我也有同样的问题。(Django 1.8教程)。 然后,在settings.py中,在BASE_DIR定义之后,我添加了一个print语句

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(BASE_DIR)
在命令行中,我输入:

python manage.py runserver
查看BASE_DIR的值。结果表明,BASE_DIR显示的文件夹比polls高一个文件夹

然后,我在settings.py中更改了模板定义,如下所示:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'polls', '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',
        ],
    },
},
]


它成功了。

我在Django 1.11教程中遇到了同样的问题,直到我意识到/templates需要与/polls和/mysite处于同一级别。你确定你的网站结构是你说的那样吗?应该是这样的:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Polls Administration') }}</a></h1>
{% endblock %}
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
        __init__.py
        admin.py
        migrations/
            __init__.py
            0001_initial.py
        models.py
        static/
            polls/
                images/
                    background.gif
                style.css
        templates/
            polls/
                detail.html
                index.html
                results.html
        tests.py
        urls.py
        views.py
    templates/
        admin/
            base_site.html
如果这不起作用,您是否尝试过在settings.py中更改BASE_DIR?你可能有点落伍了。修改为:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'mysite', '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',
        ],
    },
},
]

我在Django 1.11教程中遇到了同样的问题,直到我意识到/templates需要与/polls和/mysite处于相同的级别。你确定你的网站结构是你说的那样吗?应该是这样的:

{% extends "admin/base.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Polls Administration') }}</a></h1>
{% endblock %}
mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
        __init__.py
        admin.py
        migrations/
            __init__.py
            0001_initial.py
        models.py
        static/
            polls/
                images/
                    background.gif
                style.css
        templates/
            polls/
                detail.html
                index.html
                results.html
        tests.py
        urls.py
        views.py
    templates/
        admin/
            base_site.html
如果这不起作用,您是否尝试过在settings.py中更改BASE_DIR?你可能有点落伍了。修改为:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'mysite', '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',
        ],
    },
},
]

你把settings.py文件放在哪里了?你能删除或重命名\django\contrib\admin\templates\admin\base.html看看django在哪里搜索吗?我也有同样的问题…你把settings.py文件放在哪里了?你能删除或重命名\django\contrib\admin\templates\admin\base.html看看django在哪里搜索吗?我有同样的问题。。。