티스토리 뷰
(macOS)[python] django-erp : login, logout, signup, signup_waiting
jinozpersona 2021. 11. 5. 02:11INTRO
Python 3.10.0
Django 3.2.8
signup/login
- config/urls
{SublimeText} config/urls.py
from django.contrib import admin
from django.urls import path, include
from home import urls, views
from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path('', TemplateView.as_view(template_name='welcome.html'), name='welcome'),
path('login/', auth_views.LoginView.as_view(template_name='login.html'), name='login'),
path('signup/', views.signup, name='signup'),
path('home/', include("home.urls")),
]
- templates
{SublimeText} templates/welcome.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome_PERSONA_ERP</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="{% static 'css/style_mysite.css' %}">
</head>
<body>
<div id="container">
<div id="header">
<div class="logo">
<a href="{% url 'welcome' %}"><img src="{% static 'img/logo_w_persona.png' %}" width="140" height="38"></a>
</div>
<div class="h-item">
<a href="{% url 'login' %}"><input type="submit" value="LogIn"></a>
<a href="{% url 'signup' %}"><input type="submit" value="SignUp"></a>
</div>
</div>
<div id="m-content">
<div class="m-body">
<h2>main_body</h2>
<h2>Thanks to visit PERSONA ERP</h2>
<h2>----main-end----</h2></br>
</div>
</div>
<div id="s-content">
<div class="s-body">
<h2>signup form</h2>
{% block logform %}
{% endblock %}
</div>
</div>
<div id="footer">
<p>Copyright © PERSONA All rights reversed.</p>
</div>
</div>
</body>
</html>
signup
- form error
{SublimeText} templates/form_errors.html
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger">
<strong>{{ field.label }}</strong>
{{ error }}
</div>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger">
<strong>{{ error }}</strong>
</div>
{% endfor %}
{% endif %}
- signup/signup_waiting
{SublimeText} templates/signup.html
{% extends 'welcome.html' %}
{% block logform %}
<div id="s-content">
<div>
<form method="POST" class="post-form">
{% csrf_token %}
{% include "form_errors.html" %}
<div>
<label for="username">User-ID</label><br>
<input type="text" name="username" id="username"
value="{{ form.username.value|default_if_none:'' }}">
</div>
<div>
<label for="password1">Password</label><br>
<input type="password" name="password1" id="password1"
value="{{ form.password1.value|default_if_none:'' }}">
</div>
<div>
<label for="password2">Password Confirm</label><br>
<input type="password" name="password2" id="password2"
value="{{ form.password2.value|default_if_none:'' }}">
</div>
<div>
<label for="email">E-mail</label><br>
<input type="text" name="email" id="email"
value="{{ form.email.value|default_if_none:'' }}">
</div>
<a href="{% url 'signup_waiting' %}"><button type="submit">Create</button></a>
</form>
</div>
</div>
{% endblock %}
{SublimeText} templates/signup_waiting.html
{% extends 'welcome.html' %}
{% block logform %}
<div id="s-content">
<h3>{{ user.username }}님 반갑습니다~^^</h3>
<h3>{{ user.email }}로 관리자 승인 여부 확인 후 회신 예정입니다.</h3>
</div>
{% endblock %}
login
- login 후 home으로 이동
{SublimeText} templates/base.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}{{ section.title }}{% endblock %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="{% static 'css/style_mysite.css' %}">
</head>
<body>
<div id="container">
<div id="header">
<div class="logo">
<a href="{% url 'welcome' %}"><img src="{% static 'img/logo_w_persona.png' %}" width="140" height="38"></a>
</div>
<div class="h-item">
{% if user.is_authenticated %}
<a href="{% url 'logout' %}"><input type="submit" value="{{ user.username }} (Logout)"></a>
{% else %}
<a href="{% url 'login' %}"><input type="submit" value="Login"></a>
{% endif %}
</div>
<div class="search-item">
<input type="search" name="q" placeholder="Search query">
<input type="submit" value="Go!">
</div>
</div>
<!-- Main block -->
<div id="m-content">
{% block content1 %}
{% endblock %}
</div>
<!-- Sub block -->
<div id="s-content">
{% block content2 %}
{% endblock %}
</div>
<div id="footer">
<p>Copyright © PERSONA All rights reversed.</p>
</div>
</div>
</body>
</html>
{SublimeText} home/welcome_home.html
{% extends 'base.html' %}
<!--navbar_top -->
<!-- Main block -->
{% block content1 %}
<h2>After Login</h2>
<h2>{{ user.username }}님 반갑습니다.</h2>
{% endblock %}
<!-- End Main block -->
<!-- Sub block -->
{% block content2 %}
<h2>Notice Table</h2>
{% endblock %}
<!-- End Sub block -->
{SublimeText} home_views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
# Create your views here.
def signup(request):
if request.method == 'POST':
if request.POST['password1'] == request.POST['password2']:
user = User.objects.create_user(username=request.POST['username'], password=request.POST['password1'], email=request.POST['email'], is_active=False)
auth.login(request, user)
return render(request, 'signup_waiting.html', {'user':user})
return redirect('/')
return render(request, 'signup.html')
@login_required
def welcome_home(request):
# return HttpResponse("HttpResponse : /home/templates/welcome_home.html.")
return render(request, 'welcome_home.html')
--------- 실행화면 : runserver ---------
chrome browser : http://localhost:8000
- login 클릭 이동
chrome browser : http://localhost:8000/login
- signup 클릭 이동
chrome browser : http://localhost:8000/signup
- login 후 home 이동
chrome browser : http://localhost:8000/home
- signup 후 signup_waiting page 이동
chrome browser : http://localhost:8000/signup_waiting
logout 후 welcome page 이동
chrome browser : http://localhost:8000/
'python > django_ERP2' 카테고리의 다른 글
(macOS)[python] django-erp : templates 분리 (1) mysite (0) | 2021.11.07 |
---|---|
(macOS)[python] django-erp : bootstrap 적용 (0) | 2021.11.05 |
(macOS)[python] django-erp : app 생성 (0) | 2021.11.04 |
(macOS)[python] django-erp : Django 초기설정 (0) | 2021.11.01 |
(macOS)[python] django-erp : pyenv 개발환경 설정 (0) | 2021.10.25 |
- Total
- Today
- Yesterday
- pyserial
- SSH
- git
- github
- CSV
- Templates
- Regression
- raspberrypi
- 확진
- Pandas
- server
- analysis
- MacOS
- 라즈베리파이
- Python
- Raspberry Pi
- vscode
- 코로나19
- 코로나
- ERP
- COVID-19
- DS18B20
- template
- Django
- DAQ
- Model
- arduino
- r
- sublime text
- 자가격리
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |