DRF does not work with wagtail
<p>I have used DRF for rest api and puput for blog which is built on top of the wagtail. Before using puput, my rest api used to work but not now. For example when i try to open the url <strong><a href="http://localhost:8000/rest-api/ui/tab/" rel="nofollow">http://localhost:8000/rest-api/ui/tab/</a></strong> i get following error </p>

<blockquote>
  <p>Page not Found 404 error Raised by:   wagtail.wagtailcore.views.serve</p>
</blockquote>

<p><strong>settings.py</strong></p>

<pre><code>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
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code>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)),
]
</code></pre>

<p><strong>ui_mgmt/urls.py</strong></p>

<pre><code>url(r'^ui/tabs/$', tab_list, name='tab_list'),
</code></pre>

<p><strong>ui_mgmt/views.py</strong></p>

<pre><code>@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)
</code></pre>

<p>Why my DRF is not working? I get the same error for every rest api call.</p>

<p>change the order of your url patterns.. puput should (probablly) the last element</p>

<pre><code>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
]
</code></pre>

<p>Hope this helps</p>

python django python-3.x django-rest-framework wagtail