상세 컨텐츠

본문 제목

회원가입 구현

django

by 개복신 개발자 2021. 7. 26. 15:19

본문

728x90
반응형

views.py

from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse, reverse_lazy
from django.views.generic import CreateView
from django.contrib.auth.forms import UserCreationForm
from .models import *

# Create your views here.

class AccountCreateView(CreateView):
    model = User
    form_class = UserCreationForm
    success_url = reverse_lazy('accountapp:hello_wrold')
    template_name = 'accountapp/create.html'

-view.py에 클래스 기반으로 작성

-CreateView 클래스를 상속받음(장고 기본 제공)

-model=User: 장고 제공하는 모델(db)

-form_class는 형식

-success_url 회원가입 성공시 이동하는 url

-template_name 적용되는 html 연결


urls.py

accountapp내의 urls.py

class based view이기 때문에 AccountCreateView.as_view()라고 작성해야 됨


html

{% extends 'base.html' %}

{% block content %}
<div>
    <form action="{%url 'accountapp:create' %}" method="POST">
        {% csrf_token %}
        {{ form }}

        <input type="submit" value="" class="btn btn-primary">
    </form>
</div>


{% endblock %}

 

반응형

'django' 카테고리의 다른 글

Bootstrap 이용한 form 디자인 정리  (0) 2021.08.13
login/logout 구현  (0) 2021.08.11
DB 정보 접근 및 장고 템플릿 내 for loop  (0) 2021.07.22
텍스트 작성 내용 보이기 (17강)  (0) 2021.07.19
http 프로토콜 (15~16강)  (0) 2021.07.19

관련글 더보기

댓글 영역