Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

Change the Django Rest Framework Default Router api root?

In development,

my defaultrouter works along the base url/domain of http://127.0.0.1:8000/, however the api is going to be hosted on http://website.com/test/location/

How do i change the default default router location so apiview,inner links, and the api work at http://website.com/test/location/ as the api root?

question from:https://stackoverflow.com/questions/66051095/change-the-django-rest-framework-default-router-api-root

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your default router has nothing to deal with the domain. It only generates patterns to be matched after the domain name.

Let's say you have the following default router:

router = routers.DefaultRouter()
router.register('users', views.UserViewSet)

That means /users/ will be matched to some view no matter what the domain is. So for the developement process it will match 127.0.0.1:800/users/ and localhost:8000/users/. After you deploy it to website.com/, it will match website.com/users/

In most cases the domain is changed automatically as you deploy it to some platform or server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...