Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass multiple url arguments to RedirectView?
    primarykey
    data
    text
    <p>I have a form which uses redirect view to create a record when the user pushes a button. This works fine when there is only one argument to be passed. However, I now wish to do this based on two parameters <code>configuration_pk</code> and <code>type_pk</code> and it returns an error:</p> <p><code>Reverse for 'new_conf_cert' with arguments '()' and keyword arguments '{u'type_pk': 1, u'configuration_pk': 2}' not found.</code></p> <p>The template snippet calling this is:</p> <pre><code>&lt;div id="menu"&gt; &lt;a&gt;&lt;img width="56pt" src="/static/icon-calibrate.svg"&gt;&lt;/a&gt;&lt;br /&gt; &lt;div style="display: none"&gt; {% for type in object.typelist %} &lt;form action="{% url 'new_conf_cert' configuration_pk=object.id type_pk=type.id %}" method="post" onsubmit="return confirm('Are you sure you want to calibrate all instruments in the {{object}} configuration?')"&gt;{% csrf_token %} &lt;input type="submit" value="Calibrate {{type}}s" /&gt; &lt;/form&gt; {% endfor %} &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $('#menu &gt; a').click(function(){ $(this).next().next().slideToggle(); return false; }); &lt;/script&gt; </code></pre> <p>The relevant line in urlconf is<br> <code>url(r'^add/conf_certificate/(?P&lt;configuration_pk&gt;)/(?P&lt;type_pk&gt;\d+)/$', 'Tank.views.new_conf_cert', name='new_conf_cert'),</code></p> <p>And the views.py section looks like this:</p> <pre><code>class AddConfigurationCertificateView(RedirectView): http_method_names = ['post'] def get_redirect_url(self, *args, **kwargs): url = '/Tank/configurations/%s/' % self.kwargs['configuration_pk'] return url def post(self, request, *args, **kwargs): conf = Configuration.objects.get(id=self.kwargs['configuration_pk']) caltype = InstrumentType.objects.get(id=self.kwargs['type_pk']) for inst in conf.instruments.all(): if inst.kind == caltype: CalibrationCertificate.objects.create(instrument=inst, expires=timezone.now()+timedelta(days=inst.kind.duration), issued=timezone.now(), issued_by=request.user) return super(AddConfigurationCertificateView, self).post(request, *args, **kwargs) new_conf_cert = AddConfigurationCertificateView.as_view() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload