How to use django template tag 'url' with django 1.6?
Question: I'm using Python 2.7.5, django 1.6.2 and bootstrap 3.

I know the template tag `{% url %}` changed since django 1.5. I've read the
[documentation for reverse
url](https://docs.djangoproject.com/en/1.6/topics/http/urls/#reverse-
resolution-of-urls) on django website but I must do something wrong because I
can't get it to work.

Here is my teams/urls.py, I use the named url `delete_team_url` :

    
    
    from django.conf.urls import patterns, url
    import teams.views
    
    urlpatterns = patterns('',
        url(r'^$', teams.views.index, name='teams_index'),
        url(r'^new-team/$', teams.views.index, {'add_new_team':True}, name='teams_index_new_team'),
        url(r'^delete/$', teams.views.delete_team, name='delete_team_url'), 
    
    )
    

Here is the project global urls.py :

    
    
    from django.conf.urls import patterns, include, url
    from django.contrib import admin
    
    import bbch.views
    import auth.views
    admin.autodiscover()
    
    urlpatterns = patterns('',
        url(r'^admin/', include(admin.site.urls)),
        url(r'^rosetta/', include('rosetta.urls')),
        url(r'^i18n/', include('django.conf.urls.i18n')),
    
        url(r'^auth/', include('auth.urls', namespace="auth")),
        url(r'^rules/', include('rules.urls', namespace="rules")),
        url(r'^forum/', include('forum.urls', namespace="forum")),
        url(r'^teams/', include('teams.urls', namespace="teams")),
    
        url(r'^accounts/login/$', auth.views.connection, {'log_required':True}),
        url(r'^home/log_in/$', bbch.views.home, {'log_message':True}, name="home_log_message"),
        url(r'^home/$', bbch.views.home, name="bbch"),
        url(r'^$',  bbch.views.home, name="bbch"),
    
    )
    

Here is my view (I'm using dummy `id=0` just for the test) :

    
    
    def delete_team(request):
        team = teams.models.Team.objects.get(id=0)
        team.delete()
    
        return render(request, 'teams/index.html', context)
    

And finally here is my html code part where I use the reverse url template tag
:

    
    
    <div class="row">
        <div class="col-md-2">
            <a href="{% url 'delete_team_url' %}" class="btn btn-danger delete-team"><span class="glyphicon glyphicon-trash"></span> {% trans "Delete team" %}</a>
        </div>
        <div class="col-md-2">
            <a href="#" class="btn btn-info edit-team"><span class="glyphicon glyphicon-pencil"></span> {% trans "Edit team" %}</a>
        </div>
        <div class="col-md-2 col-md-offset-6 btn-right">
            <a href="#" class="btn btn-success add-player"><span class="glyphicon glyphicon-plus"></span> {% trans "Add a player" %}</a>
        </div>
    </div>
    

I get the following error :

    
    
    NoReverseMatch at /teams/
    Reverse for 'delete_team_url' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
    

Let me know if you need more informations ! Thank you for your help !

* * *

Edit : Here is the `teams.views.index` (asked by weasel) :

    
    
    @login_required
    def index(request, add_new_team=False) :
        if request.method == 'POST' :
    
            t_form = teams.forms.CreateTeamForm(request.POST)
            p_form = teams.forms.CreatePlayerForm(request.POST)
            t_errors = t_form.errors
            p_errors = p_form.errors
    
            if t_form.is_valid() :
                create_new_team = t_form.cleaned_data['new_team']
            else : 
                create_new_team = False
    
            if p_form.is_valid() :
                add_player = p_form.cleaned_data['new_player']
            else :
                add_player  = False
            #import ipdb; ipdb.set_trace()
            if create_new_team :
                if t_form.is_valid() :
    
                    name = t_form.cleaned_data['name']
                    reroll = t_form.cleaned_data['reroll']
                    apo = t_form.cleaned_data['apo']
                    assistant = t_form.cleaned_data['assistant']
                    pompom = t_form.cleaned_data['pompom']
                    pop = t_form.cleaned_data['pop']
                    value = t_form.cleaned_data['value']
                    treasury = t_form.cleaned_data['treasury']
    
                    team = teams.models.Team(
                        name=name,
                        coach=request.user.username,
                        reroll=reroll,
                        apo=apo,
                        assistant=assistant,
                        pompom=pompom,
                        pop=pop,
                        value=value,
                        treasury=treasury,
                        )
                    team.save()
    
                    team_set = teams.models.Team.objects.filter(coach=request.user.username)
                    player_form = teams.forms.CreatePlayerForm()
                    context = {
                        'create_player_form' : player_form,
                        'teams' : team_set,
                        'username' : request.user,
                        'loged_in' : request.user.is_authenticated(),
                    }
                    return render(request, 'teams/index.html', context)
    
            elif add_player :
                if p_form.is_valid() :
    
                    name = p_form.cleaned_data['name']
                    position = p_form.cleaned_data['position']
                    number = p_form.cleaned_data['number']
                    team_id = request.POST.get('team_id')
                    team = teams.models.Team.objects.get(coach=request.user.username, id=team_id)
    
                    team.player_set.create(name=name, position=position, number=number)
                    team.size = team.player_set.count()
                    team.save()
    
                    team_set = teams.models.Team.objects.filter(coach=request.user.username)
                    player_form = teams.forms.CreatePlayerForm()
                    context = {
                        'tab_id': team.id,
                        'create_player_form' : player_form,
                        'teams' : team_set,
                        'username' : request.user,
                        'loged_in' : request.user.is_authenticated(),
                    }
                    return render(request, 'teams/index.html', context)
    
            else :
                team_set = teams.models.Team.objects.filter(coach=request.user.username)
                team_form = teams.forms.CreateTeamForm()
                player_form = teams.forms.CreatePlayerForm()
    
                context = {
                'create_player_form' : player_form,
                'create_team_form' : team_form,
                'alert_form_player' : p_errors,
                'alert_form_team' : t_errors,
                'teams' : team_set,
                'username' : request.user,
                'loged_in' : request.user.is_authenticated(),
                }
    
                return render(request, 'teams/index.html', context)
    
        elif request.method == 'GET' :
            team_set = teams.models.Team.objects.filter(coach=request.user.username)
            team_form = teams.forms.CreateTeamForm()
            player_form = teams.forms.CreatePlayerForm()
    
            context = {
                'add_new_team': add_new_team,
                'create_player_form' : player_form,
                'create_team_form' : team_form,
                'teams' : team_set,
                'username' : request.user,
                'loged_in' : request.user.is_authenticated(),
            }
    
            return render(request, 'teams/index.html', context)
    


Answer: Perhaps because of the missing `$` (dollar) sign at the end of your
urlpatterns you're getting this error.

You should perhaps try this:

    
    
    url(r'^new-team/$' ...),
    url (r'^delete/$' ...),
    

**UPDATE:**

Okay, got it. You're using namespace in your urls which is why you've to use
`{% url %}` tag something like below:

    
    
    <a href="{% url 'teams:delete_team_url' %}" ... > ... </a>
    

