Url with period "." in Django Rest Framework

0

I have the following model with primary_key=True specified

classTeam(models.Model):
    name = models.CharField(
        max_length=64,
        primary_key=True,
    )
    ... other fields

My serializer is the following:

classTeamSerializer(serializers.ModelSerializer):
   classMeta:
        model = Team
        fields = ('url', 'name',) # and another fields

My urls.py

router = routers.DefaultRouter()
router.register(r'teams', TeamViewSet)

urlpatterns = [
    url(r'^api/', include(router.urls)),

    # I am not sure if this url is right. I repeat of include(router.urls)
    url(r'^api/teams/(?P<name>[-\w.]+)/', include(router.urls)),

    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

Then, when I create a Team object with the name attribute containing a period. for example Latinos F.C. , I go to the url rest and I get:

As an alternative, I see that the attribute lookup_value_regex exists. I am NOT continuing how to use it.

In this answer is used with a basic regular expression, but if I use it, any Team object is not accessed for the rest url

How can I get a url of type /api/teams/Name F.C. in my serialized model Team ?

    
asked by bgarcial 11.01.2017 в 06:23
source

0 answers