【发布时间】:2014-10-27 09:09:50
【问题描述】:
我正在创建一个 Django Web 应用程序并遇到了以下问题。
我创建了一个名为 teamList.html 的新 html 页面,当单击主页上的 href 超链接时,应该重定向到 teamList 页面。浏览器中以http://127.0.0.1:8000/开头的url变成了http://127.0.0.1:8000/teamList,但是下面的页面并没有改变,而是重新加载了起始页面。
当前应用程序在 html 中处理登录和主页(默认登录后显示图形):
#index.html
<body>
<img src="{% static "myApp/images/logo.gif" %}" alt="logo" />
{% if user.is_authenticated %}
<p>currently logged in as: {{ user.first_name }} {{ user.last_name }}
<p><a href="/logout">logout</a>
<p><a href="/teamList">Team List</a>
<div id="radarChart">
{% block radarChartBlock %}{% endblock %}
</div>
{% else%}
<div id="login">
{% block login %}{% endblock %}
</div>
{% endif %}
</body>
我的 urls.py 看起来像这样:
from django.conf.urls import patterns, url
from myApp import views
urlpatterns = patterns('',
#http://localhost:8000/
url(r'^$', views.index, name='index'),
url(r'^/teamList/$', views.renderTeamList, name='teamList')
)
编辑:我的 teamList.html 的 views.py 方法如下所示:
from django.shortcuts import render
from django.views.generic.base import TemplateView
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from myApp.models import FocusArea
from myApp.tables import TeamTable
from django_tables2 import RequestConfig
def renderTeamList(request):
table = TeamTable()
RequestConfig(request).configure(table)
return render(request, 'teamList.html', {'table': table})
【问题讨论】:
-
你的观点是?这就是你要重定向的地方。
-
视图返回正确吗?
标签: python html django django-urls