3

I have the following settings:

The urls.py of the project's app:

urlpatterns = [
    url(r'^main/', include('main.urls', namespace='main')),
]

The main app's urls.py:

urlpatterns = [
    url(r'^add/$', views.add, name='add'),
]

I am trying to create an URL as /main/add/whatever/ in a template, hypothetically as follows:

<form method="POST" action="{% url 'main:add' %}" + "whatever/">

How do I do that?

1 Answer 1

5

Just use:

<form method="POST" action="{% url 'main:add' %}whatever/">

The code inside the curly braces will be rendered by your template system, and will precede the whatever, thus generating the following HTML:

<form method="POST" action="/main/add/whatever/">
Sign up to request clarification or add additional context in comments.

1 Comment

Works like a charm! I didn't expect it to be so simple. Thanks a lot.

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.