I am trying to make this url patterns work, but I am not getting anywhere.I get a page not found error.The url in my url bar is http://127.0.0.1:8000/tags/?Python
if I select python slug, but it does not use the defined url.
What I want to do is, open a new template with information related to slug.
This is my view:
def tags(request,slug):
verse = get_object_or_404(Tag, slug=slug)
return render(request, 'tags.html',{'verse':verse})
Here is my url:
url(r'^tags/(?P<slug>[\W-]+)/$', views.tags),
This is my template:
Tagged under - {% for i in verse.tags.all%}<a href='/tags'>{{ i }} | </a>{% endfor %}
I have tried passing a query string in template as:
/tags/q={{i}}
I have also tried to use:
{% url tags i.slug %}
(based on Slug Url Regex in Django)
But so far nothing is working. I want to open the tags template with the selected slug being displayed.
you must set a name In url
similar below:
url(r'^tags/(?P<slug>.+)/$', views.tags, name='tags'),
in template change your url
tag to:
{% url "tags" slug=i.slug %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With