correct way to obtain the rest of the parameters of URL in Django rest framework
<p>Hi everyone I am using  Django rest framework to create an API</p>

<p>In my URLs.py file I have this</p>

<pre><code>  url(r'^cpuProjects/$', cpuProjectsViewSet.as_view({'get': 'list'})),
  url(r'^cpuProjects/(?P&lt;project_name&gt;[a-zA-Z0-9]+)$', cpuProjectsViewSet.as_view({'get': 'retrieve'})),
</code></pre>

<p>This work perfectly, and I have this to url</p>

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

<p>in my retrieve function, I have this to get the parameter</p>

<pre><code>  def retrieve(self, request, project_name=None):
    try:
      opc = self.kwargs.get(self.lookup_url_kwarg)
      print(opc)
      ...
</code></pre>

<p>Now, I add this to my URLs.py files</p>

<pre><code>url(r'^cpuProjects/(?P&lt;project_name&gt;[a-zA-Z0-9]+/[a-zA-Z0-9]+)$', cpuProjectsViewSet.as_view({'get': 'retrieve'})),


http://127.0.0.1:8000/cpuProjects/name_project/whatever_string_here
</code></pre>

<p>My <code>print(opc)</code> in this last case return this <code>ad/pending</code>.</p>

<p>Is this the correct way to obtain the rest of the parameters of URL in Django rest framework?</p>

<p>You have that entire path of the url wrapped in this same regex named group. You can instead separate the trailing part by putting it in a different group:</p>

<pre><code>url(r'^cpuProjects/(?P&lt;project_name&gt;[a-zA-Z0-9]+)/(?P&lt;status&gt;[a-zA-Z0-9]+)$', ...),
</code></pre>

<p>And in your view:</p>

<pre><code>def retrieve(self, request):
    try:
        opc = self.kwargs.get(self.lookup_url_kwarg)
        status = self.kwargs.get('status')
        ...
</code></pre>

python django django-rest-framework django-cms