создана точка доступа для создания статьи, модель статьи сохраняется в БД
This commit is contained in:
parent
2dcb938970
commit
fa575c845a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
.idea/
|
.idea/
|
||||||
.python-version
|
.python-version
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
.env
|
||||||
|
__pycache__/
|
||||||
|
identifier.sqlite
|
0
cms/__init__.py
Normal file
0
cms/__init__.py
Normal file
22
cms/migrations/0001_initial.py
Normal file
22
cms/migrations/0001_initial.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.1.4 on 2022-12-09 17:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Article',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(max_length=100)),
|
||||||
|
('body', models.TextField()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
cms/migrations/__init__.py
Normal file
0
cms/migrations/__init__.py
Normal file
6
cms/models.py
Normal file
6
cms/models.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Article(models.Model):
|
||||||
|
title = models.CharField(max_length=100)
|
||||||
|
body = models.TextField()
|
6
cms/urls.py
Normal file
6
cms/urls.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from .views import ArticleView
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('articles/', ArticleView.as_view())
|
||||||
|
]
|
18
cms/views.py
Normal file
18
cms/views.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from json import JSONDecoder
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from django.views import View
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
|
from cms.models import Article
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(csrf_exempt, name='dispatch')
|
||||||
|
class ArticleView(View):
|
||||||
|
def post(self, request):
|
||||||
|
article_data = JSONDecoder().decode(request.body.decode())
|
||||||
|
article = Article.objects.create(**article_data)
|
||||||
|
response = {'ok': True}
|
||||||
|
return JsonResponse(response)
|
@ -14,8 +14,9 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('cms/', include('cms.urls')),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user