DRF 不适用于鹡鸰

DRF does not work with wagtail

我已经将 DRF 用于休息 api 并将 puput 用于构建在 wagtail 之上的博客。在使用 puput 之前,我的休息 api 曾经可以工作,但现在不行了。例如,当我尝试打开 url http://localhost:8000/rest-api/ui/tab/ 时,出现以下错误

Page not Found 404 error Raised by: wagtail.wagtailcore.views.serve

settings.py

DJANGO_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
]

THIRD_PARTY_APPS = [
    # rest framework
    'rest_framework',

    # third party apps
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'ckeditor',
]

MACHINA_APPS = [
    'mptt',
    'haystack',
    'widget_tweaks',
    'django_markdown',
]

LOCAL_APPS = [
    'ui_mgmt',                # UI manager - tabs, cards etc
    'faq',                    # faq
]

PUPUT_APPS = [
    'wagtail.wagtailcore',
    'wagtail.wagtailadmin',
    'wagtail.wagtaildocs',
    'wagtail.wagtailsnippets',
    'wagtail.wagtailusers',
    'wagtail.wagtailimages',
    'wagtail.wagtailembeds',
    'wagtail.wagtailsearch',
    'wagtail.wagtailsites',
    'wagtail.wagtailredirects',
    'wagtail.wagtailforms',
    'wagtail.contrib.wagtailsitemaps',
    'wagtail.contrib.wagtailroutablepage',
    'compressor',
    'taggit',
    'modelcluster',
    'puput',
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + MACHINA_APPS + LOCAL_APPS + get_machina_apps() + PUPUT_APPS

urls.py

from ui_mgmt import urls as ui_mgmt_urls
urlpatterns = [
    url(r'^accounts/', include(allauth_urls)),
    url(r'^admin/', admin.site.urls),
    url(r'^forum/', include(board.urls)),
    url(r'', include('puput.urls')),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^rest-api/', include(ui_mgmt_urls)),
]

ui_mgmt/urls.py

url(r'^ui/tabs/$', tab_list, name='tab_list'),

ui_mgmt/views.py

@api_view(['GET','POST'])
def tab_list(request, format=None):
    if not request.user.is_authenticated():
        return Response(status=status.HTTP_401_UNAUTHORIZED)

    user = request.user
    if request.method == 'GET':
        tabs = Tab.objects.filter(belongsTo=user)
        serialized_data = ExtendedTabSerializer(tabs, many=True)
        return Response(serialized_data.data)

    elif request.method == 'POST':
        serialized_data = TabSerializer(data=request.data)
        if serialized_data.is_valid():
            serialized_data.save(belongsTo=user)
            newTab = ExtendedTabSerializer(Tab.objects.get(id=serialized_data.data['id']))
            return Response(newTab.data,status=status.HTTP_201_CREATED)

        return Response(serialized_data.errors,status=status.HTTP_400_BAD_REQUEST)

为什么我的 DRF 不工作?每次休息 api 调用我都会得到同样的错误。

更改 url 模式的顺序.. puput 应该(可能)是最后一个元素

urlpatterns = [
  url(r'^accounts/', include(allauth_urls)),
  url(r'^admin/', admin.site.urls),
  url(r'^forum/', include(board.urls)),
  url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
  url(r'^rest-api/', include(ui_mgmt_urls)),
  url(r'', include('puput.urls')),  # it will match the rest of patterns
]

希望对您有所帮助