Re: Write urls without regex in DRF

2019-05-23 Thread nm
Yes, it's possible to write this code without using regexp, and it should 
work the same.

If you have a look at the source code of the routers, there's a method 
`get_urls` in SimpleRouter (you can find it here 
https://github.com/encode/django-rest-framework/blob/master/rest_framework/routers.py),
 
which, among others, does:

regex = route.url.format(
prefix=prefix,
lookup=lookup,
trailing_slash=self.trailing_slash
)


where `route.url` is something like 

url=r'^{prefix}/{lookup}{trailing_slash}$',


and `prefix` is the first argument you pass to `router.register` - in your 
case, an empty string:

def register(self, prefix, viewset, basename=None, base_name=None)


It does not seem to matter whether you put `prefix=r''` or `prefix=''`, the 
ultimate url regex looks the same.
Disclaimer: I assume you're using the latest version of DRF (3.9.x); I 
haven checked how the code looks in older versions. 

On Wednesday, 22 May 2019 17:20:20 UTC+2, Rounak Jain wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e929c4c9-a174-434d-bda9-9000e5cf8892%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain

I cannot see any reply 
On Thursday, May 23, 2019 at 7:56:54 AM UTC+5:30, Kevin Jay wrote:
>
> kevin@kjay,net
>
> On Wed, May 22, 2019 at 10:19 AM Rounak Jain  > wrote:
>
>>
>> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
>> possible to write the code below without using regex?
>> Thanks
>>
>> from .views import TaskViewSet
>> from rest_framework.routers import DefaultRouter
>>
>> router = DefaultRouter()
>> router.register(r'', TaskViewSet, basename='task')
>> urlpatterns = router.urls
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a1efd52-570c-445f-b4d8-61cd13ae67d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Kevin Jay
kevin@kjay,net

On Wed, May 22, 2019 at 10:19 AM Rounak Jain  wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEtabwdw6%2BZofc4dLdHbvMM9nzdMc0Yd_uCqUnFNWAHE2wn9ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
Thanks for the reply. I understand how to use them in urls.py when creating
normal routes but here in case of drf, it would help if you could show me
how to do it

On Wed, May 22, 2019 at 10:11 PM Onasanya Tunde 
wrote:

> Use Django2.X
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/67314c66-6d50-4390-80de-67d8151fe9a0%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANNuxWNacKstGmD2jwy3r3NYKf_R4BtoqMTBiBoTEaDAL5eb-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Onasanya Tunde
Use Django2.X

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67314c66-6d50-4390-80de-67d8151fe9a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Write urls without regex in DRF

2019-05-22 Thread Rounak Jain
I am using DRF Viewsets to auto-generate URLs for different views. Is it
possible to write the code below without using regex?
Thanks

from .views import TaskViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'', TaskViewSet, basename='task')
urlpatterns = router.urls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANNuxWNoPGePbAcxnWqzMgeioYXKXwD1Yn-H_2-FN774MdsbbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.