A
A
Arti-Jack2018-04-19 12:43:24
Django
Arti-Jack, 2018-04-19 12:43:24

How to set up urls correctly so that when a GET request to api does not give an error code 404?

I have a django + vue project. I start the local server, I start the client. The page is displayed, the server is started. Vue elements send a GET request to the server, which produces the following log:

Not Found: /api/mark_read
[19/Apr/2018 09:35:43] "GET /api/mark_read?id=%7B%7D HTTP/1.1" 404 2205

And when you try to make a GET request directly to the server, everything freezes (although earlier it at least showed an error code):
http GET "http://localhost:8000/api/v1/messages
So, the elements:
urls which is the main one:
from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^api/v1/', include('webapp.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^api-auth/', include('rest_framework.urls')),

urls which for the app:
from rest_framework import routers
from .views import MessageViewSet

# Создаем router и регистрируем наш ViewSet
router = routers.DefaultRouter()
router.register(r'message', MessageViewSet)

# URLs настраиваются автоматически роутером
urlpatterns = router.urls

Component-Model:
from __future__ import unicode_literals

from django.db import models

# Модель - "СообщениеИзКосмоса"
class Message(models.Model):
  msg_date = models.DateTimeField(auto_now_add=True)
  text = models.TextField()
  readed = models.BooleanField()

How can I fix this problem and what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question