Multi parameters in url django -


maybe question repeated can't find solution need. need pass 2 differents parameters 1 url in detailview (im not working function views, of possible solutions have found function views). have views done not make sense put here because not working. how can achieve this? example:

url(r'^crear-puntointeraccion/(?p<pk>[-_\w]+)/(?p<point_id>[-_\w]+)/$' 

and if not find pk or point_id show 404, have done takes 1 parameter, other parameter not taking because if write non-existent id anyway show result.

you can perform check overriding get_object() function of detailview.

get_object() returns object view displaying. in view, detailview perform object lookup using pk argument. before object retrieval process via pk, add check validate value of point_id parameter in url.

if point_id valid, call super() method normal object retrieval , validation pk occur. if point_id invalid, raise http404 exception.

from django.http import http404  class myview(detailview):      def get_object(self, queryset=none):         point_id = self.kwargs.get('point_id')         # write logic validate point_id here         if not check_valid_point_id(point_id): # assumed 'check_valid_point_id' function validates point_id              raise http404("invalid point id") # raise 404 exception on invalid point_id         return super(myview, self).get_object(queryset) # call super() on valid point_id 

note: in above code, have assumed check_valid_point_id() function take point_id argument validate point_id. can add logic point_id validation in function or write own logic in get_object() function itself.


Comments