pass several parameters in Django rest Framework
<p>I am new with <code>Django</code> and <code>Django rest framework</code>, I try to create several routes to get the data from the database.</p>

<p>Right now  in my <code>urls.py</code> file I have this</p>

<pre><code>router = routers.DefaultRouter()
router.register(r'cpuProjects', cpuProjectsViewSet, base_name='cpuProjects'),
</code></pre>

<p>this return this </p>

<pre><code>"cpuProjects": "http://127.0.0.1:8000/cpuProjects/"
</code></pre>

<p>and I have the possibility to do this 
 <code>http://127.0.0.1:8000/cpuProjects/</code>  => return all project
<code>http://127.0.0.1:8000/cpuProjects/ad</code> => return a particular project.</p>

<p>In my view.py I have this</p>

<pre><code>class cpuProjectsViewSet(viewsets.ViewSet):
  serializer_class = serializers.cpuProjectsSerializer
  # lookup_field = 'project_name'
  lookup_url_kwarg = 'project_name'

  def list(self, request):
    all_rows = connect_database()
    serializer = serializers.cpuProjectsSerializer(instance=all_rows, many=True)
    return Response(serializer.data)

  def retrieve(self, request, project_name=None):
    try:
      opc = {'name_proj' : project_name }
      all_rows = connect_database(opc)
    except KeyError:
        return Response(status=status.HTTP_404_NOT_FOUND)
    except ValueError:
        return Response(status=status.HTTP_400_BAD_REQUEST)
    serializer = serializers.cpuProjectsSerializer(instance=all_rows, many=True)
    return Response(serializer.data)
</code></pre>

<p>Now I want that my Url accepted something like that</p>

<p><code>http://127.0.0.1:8000/cpuProjects/ad/comments</code>
<code>http://127.0.0.1:8000/cpuProjects/ad/ussing</code>
<code>http://127.0.0.1:8000/cpuProjects/ad/process</code></p>

<p>For this I add this new url</p>

<pre><code>router.register(r'cpuProjects/([a-zA-Z0-9]+)$', cpuProjectsViewSet, base_name='cpuProjects'),
</code></pre>

<p>but now when I try this </p>

<pre><code>http://127.0.0.1:8000/cpuProjects/ad/ussing
</code></pre>

<p>I obtain "page no found"</p>

<p>I understood that this URL have to call to retrieve function to get the parameters, so, why this error?</p>

<p>This URL don't do the same process like </p>

<pre><code>http://127.0.0.1:8000/cpuProjects/ad 
</code></pre>

<p>Thanks in advance!</p>

<p>The routers framework isn't meant to be used with several parameters .. you can manually do it with primary keys (in the regular expressions).</p>

python django django-rest-framework