1

in views.py

class LaViewSet(viewsets.ModelViewSet):

    serializer_class = IlSerializer

    def get_queryset(self):
        ilfiltro = self.kwargs['miopar']
        return models.Pippo.objects.filter(pippo=ilfiltro)

in url.py

url(r'^pippo/(?P<miopar>.+)', views.LaViewSet.as_view({'get': 'list'}), name="Serializzata"),

this is a working url:

http://127.0.0.1:8000/pippo/1

but if I put in a template:

{% url '1' 'Serializzata' %};

or

{% url 'Serializzata'?1 %};

keep getting this error:

TemplateSyntaxError: Could not parse the remainder: '?1' from ''Serializzata'?1'

2 Answers 2

3

From the docs:

url

Returns an absolute path reference (a URL without the domain name) matching a given view and optional parameters. Any special characters in the resulting path will be encoded using iri_to_uri().

This is a way to output links without violating the DRY principle by having to hard-code URLs in your templates:

{% url 'some-url-name' v1 v2 %}

So in your case:

{% url 'Serializzata' 1 %}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

<a href="{% url 'Serializzata' 1 %}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.