按照以下方式编写urls.py好吗?
urlpatterns = [
url(r'^v1/files/$', FileView.as_view(), name='api-upload'),
url(r'^v1/files/(?P<pk>\d+)$', FileView.as_view(), name='api-delete'),
url(r'^v1/files/$', FileView.as_view(), name='api-view-all'),
url(r'^v1/files/(?P<pk>\d+)$', FileView.as_view(), name='api-view-one'),
]第二个和第四个几乎是一样的。但是一个是删除,另一个是GET。
有什么改进的建议吗?谢谢。是否可以通过django.core.urlresolvers反转网址?就像下面的
发布于 2016-07-07 21:06:44
您不需要编写urls,只需在视图中定义两个方法:
# views.py
class FileView(...):
def get(self, request, *args, **kwargs):
# This method will catch the GET call
def delete(self, request, *args, **kwargs):
# This method will catch the DELETE call这样,您只需要一个url配置:
url(r'^v1/files/(?P<pk>\d+)$', FileView.as_view(), name='api-file')https://stackoverflow.com/questions/38255194
复制相似问题