0928 SeSAC(새싹) 3기 24일차

class based views

-> def get:
정보가 get으로 넘어왔을떄
-> def post:
정보가 post로 넘어왔을때

https://docs.djangoproject.com/en/3.2/topics/class-based-views/

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, re_path

from .demo_application.views import ckeditor_form_view

urlpatterns = (
    [
        re_path(r"^$", ckeditor_form_view, name="ckeditor-form"),
        re_path(r"^admin/", admin.site.urls),
        re_path(r"^ckeditor/", include("ckeditor_uploader.urls")),
    ]
    + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
)

#urls.py

re_path(r"^$", ckeditor_form_view, name="ckeditor-form"),
-> views에 있는 ckeditor_form_view로 고고~

from django.urls import reverse
from django.views import generic

from . import forms


class CkEditorFormView(generic.FormView):
    form_class = forms.CkEditorForm
    template_name = "form.html"

    def get_success_url(self):
        return reverse("ckeditor-form")


ckeditor_form_view = CkEditorFormView.as_view()

#views.py

form_class = forms.CkEditorForm -> forms에 있는 것 좀 보여줄랭?^^

from django import forms

from ckeditor.fields import RichTextFormField
from ckeditor_uploader.fields import RichTextUploadingFormField


class CkEditorForm(forms.Form):
    ckeditor_standard_example = RichTextFormField()
    ckeditor_upload_example = RichTextUploadingFormField(
        config_name="my-custom-toolbar"
    )

#forms.py

이게 바루 form.html에 띄워지는 ckeditor창!

-> views.py에 def post를 입력해야 db에 저장가능


from.django.http import HttpResponse

return HttpResponse("") -> 그냥 글자 그대로 출력

좋은 웹페이지 즐겨찾기