gpt4 book ai didi

python - Django 管理设置

转载 作者:太空宇宙 更新时间:2023-11-03 18:39:08 25 4
gpt4 key购买 nike

我正在尝试设置 django-administration 包。我已经成功安装了它,运行了manage.pysyncdb,现在正在尝试设置它。

在/home/ec2-user/srv/mysite/templates/下,我有两个文件 base.html 和 index.html。

我还有/registration/,其中包含 activate.html、logout.html 等内容...

当我到达/accounts/register 时,我得到:

Error during template rendering
In template /home/ec2-user/srv/mysite/templates/base.html, error at line 15
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

这是我的base.html

{% load i18n %}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
<link rel="stylesheet" href="/style.css" />
<title>{% block title %}User test{% endblock %}</title>
</head>

<body>
<div id="header">
{% block header %}
<a href="{% url 'index' %}">{% trans "Home" %}</a> |

{% if user.is_authenticated %}
{% trans "Logged in" %}: {{ user.username }}
(<a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a> |
<a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a>)
{% else %}
<a href="{% url 'auth_login' %}">{% trans "Log in" %}</a>
{% endif %}
<hr />
{% endblock %}
</div>

<div id="content">
{% block content %}{% endblock %}
</div>

<div id="footer">
{% block footer %}
<hr />
{% endblock %}
</div>
</body>

</html>

这是我的index.html

{% extends "base.html" %}
{% load i18n %}

{% block content %}
Index page
{% endblock %}

我是 Django 新手,因此非常感谢任何帮助和解释为什么会发生这种情况!

编辑 1这是主“mysite”的 urls.py

from django.conf.urls import patterns, include, url
from django.conf import settings

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^', include(admin.site.urls)),
url(r'^polls/', include('polls.urls',namespace = "polls")),
url(r'^accounts/', include('registration.backends.default.urls')),
)

此外,这里还有 Apache 的相关部分。请注意,我只想让 django 响应几个子网址,这就是为什么我像我一样拥有它:

WSGIScriptAlias /polls /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /admin /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /accounts /home/ec2-user/srv/mysite/apache/wsgi.py

最佳答案

您在评论中提到您不需要索引/主页:

The reason I don't have "/" is because I don't want Django to respond to everything. Only very specific suburls....

那么为什么不删除 <a href="{% url 'index' %}">{% trans "Home" %}</a> |关联?您希望它指向其他地方吗?

关于python - Django 管理设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com