I'm learning django on version 1.8.
In their documentation they suggest to use {% url %}
template tag in order to avoid hardcoding the url. But it is not working in the v1.8, and confirmed that it is deprecated in this version.
https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#url
Does anyone know any alternative ?
Update: p_index.html
{% if latest_question_list %}
<ul>
{% for que in latest_question_list %}
<li><a href="{% url 'polls:detail' que.id %}">{{ que.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p> No polls questions are availabe. </p>
{% endif %}
Above code gives me this error: 'str' object has no attribute 'regex'
When I change the href line as below, works fine!
<li><a href="/polls/{{ que.id }}/">{{ que.question_text }}</a></li>
urlpatterns in polls app:
urlpatterns = [
url(r'^$', views.index, name='view_index'),
# ex: /polls/5/
url(r'^(?P<q_no>[0-9]+)/$', views.detail, name='detail'),
# ex: /polls/5/results/
url(r'^(?P<q_no>[0-9]+)/results/$', views.results, name='results'),
# ex: /polls/5/vote/
url(r'^(?P<q_no>[0-9]+)/vote/$', views.vote, name='vote'),
]
The main urls.py is as below :
urlpatterns = [
url(r'^$', 'home.views.index'),
url(r'^polls/', include('polls.urls', namespace = 'polls')),
url(r'^android/start', 'testpage.views.androidStart'),
url(r'^admin/', include(admin.site.urls)),
]
'path.to.some_view'
dotted path syntax to specify the view is deprecated.'str' object has no attribute 'regex'
.