I'm trying to use url names to send a custom arg to my TemplateView.
Urls.py
urlpatterns = [
url(r'^$', index.as_view(template_name='index.html', gotodiv='whatis'), name='whatis'),
url(r'^$', index.as_view(template_name='index.html', gotodiv='whybepartofit'), name='whybepartofit')
]
Views.py
class index(TemplateView):
template_name = "index.html"
gotodiv = ''
def get_context_data(self, **kwargs):
context = super(index, self).get_context_data(**kwargs)
context['gotodiv'] = self.gotodiv
return context
Template
<li>
<a href="{% url 'whatis' %}">What is it?</a>
</li>
<li>
<a href="{% url 'whybepartofit' %}">Why be part of it?</a>
</li>
The problem is that it doesn't care about the url name, because the patterns match in both cases. So it always goes to the first pattern (in this example, the one with the "whatis" gotodiv arg. Is there a way to configure the pattern so it only care about the name?.
Thanks
Index. If you use lowercaseindexit looks like a function-based-view to other Django users.