2017-06-20 68 views
0

我正在使用Django版本1.10.7。目前在我的HTML我有:如何在django中使用url标记?

<a href={% url 'home' %}>Home<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-home"></span></a> 

我的项目urls.py具有

from django.conf.urls import include,url 
from django.contrib import admin 
from base import views 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^team/', include('team.urls'), name='team'), 
    url(r'^game/', include('game.urls'), name='game'), 
    url(r'^about/', include('base.urls'), name='about'), 
    url(r'^$', views.home, name='home'), 
] 

而且在views.py,

from django.shortcuts import render 

# Create your views here. 
def about(request): 
    return render(request,'base/about.html',{}) 

def home(request): 
    return render(request,'base/home.html',{}) 

这给了错误:

NoReverseMatch at/
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 
Request Method: GET 
Request URL: http://127.0.0.1:8000/ 
Django Version: 1.10.7 
Exception Type: NoReverseMatch 
Exception Value:  
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 

我该如何解决这个问题?

回答

1

尝试把你的网址,按以下顺序:

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^$', views.home, name='home'), 
    url(r'^team/', include('team.urls'), name='team'), 
    url(r'^game/', include('game.urls'), name='game'), 
    url(r'^about/', include('base.urls'), name='about'), 
] 

如果作品,这意味着在你的其他网址,包括文件的问题。