LoginSignup
10

More than 3 years have passed since last update.

posted at

Djangoのテンプレートのurlタグにパラメータをつける方法

Python 3.5.2
Django 2.0

今までurlにパラメータ渡すときは何も考えずこんな風に書いてました。

html
 <a href="{% url 'somefunc' %}?param={{param}}">

でもこんな風にもかけることを今日知りました。

html
 <a href="{% url 'somefunc' param %}">
urls.py
urlpatterns = [
    path('somefunc/<int:param>', views.somefunc, name='somefunc')
]

知らなかった。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
10