Papouche Guinslyzinho
Papouche Guinslyzinho

Reputation: 5448

How to create a link with parameter in django

Hi I am trying to create a link with paremeter but I am getting an error (Page not found)

error

Reverse for 'hexcode' with arguments '('#d4cbd0',)' not found. 1 pattern(s) tried: ['hexcode/(?P<color>\\w)$']

template

{% for color in palette_dominant_color %}
<a href="{% url 'brandcolors:hexcode' color %}" style="text-decoration:none;color:inherit">
  {{color}}
</a>
<br>
{% endfor %}

urls.py

url(r'^hexcode/(?P<color>\w)/$', ThemeView.as_view(), name="hexcode"),

views.py

class ThemeView(TemplateView):
    template_name='fabric/theme.html'

    def get_context_data(self, **kwargs):
        context = super(ThemeView, self).get_context_data(**kwargs)
        colors = Color.objects.filter(color=kwargs['color']).all()
        return context

Upvotes: 0

Views: 184

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Your regex expects a single alphanumeric character, not a hash followed by several characters.

Upvotes: 2

Cl&#233;ment Denoix
Cl&#233;ment Denoix

Reputation: 1514

Your link should be:

<a href="{% url 'brandcolors:hexcode' color=color %}" style="text-decoration:none;color:inherit">{{color}}</a>

Upvotes: 1

Related Questions