티스토리 뷰
(macOS)[python] django-erp : templates 분리 (1) mysite
jinozpersona 2021. 11. 7. 10:00INTRO
Python 3.10.0
Django 3.2.8
templates 구조화
(1) django-erp/templates/mysite : 최초 생성한 ERP
(2) django-erp/templates/bstest : bootstrap test, 하위 base 폴더에 base.html layout 별 구성 예정
(3) django-erp/templates/persona : bootstrap customize
tree 구조
── templates
├── bstest
│ ├── 401.html
│ ├── 404.html
│ ├── 500.html
│ ├── charts.html
│ ├── index.html
│ ├── layout-sidenav-light.html
│ ├── layout-static.html
│ ├── login.html
│ ├── password.html
│ ├── register.html
│ └── tables.html
├── mysite
│ ├── base.html
│ ├── form_errors.html
│ ├── login.html
│ ├── signup.html
│ ├── signup_waiting.html
│ └── welcome.html
└── persona
mysite 수정 : localhost:8000/mysite/
- settings.py
{SublimeText} settings.py
....
from pathlib import Path
import os, json
from pytz import common_timezones
from django.core.exceptions import ImproperlyConfigured
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')
TEMPLATES_MYSITE = os.path.join(BASE_DIR, 'templates', 'mysite')
TEMPLATES_TEST = os.path.join(BASE_DIR, 'templates', 'bstest')
....
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
TEMPLATES_DIR, TEMPLATES_MYSITE, TEMPLATES_TEST,
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
....
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_REDIRECT_URL = '/home/mysite/'
LOGOUT_REDIRECT_URL = '/mysite/'
- urls.py
{SublimeText} 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='persona.html'), name='persona'),
path('mysite/', TemplateView.as_view(template_name='mysite/welcome.html'), name='mysite/welcome'),
path('mysite/login/', auth_views.LoginView.as_view(template_name='mysite/login.html'), name='mysite/login'),
path('mysite/logout/', auth_views.LogoutView.as_view(), name='mysite/logout'),
path('mysite/signup/', views.signup, name='mysite/signup'),
path('mysite/signup_waiting/', TemplateView.as_view(template_name='mysite/signup_waiting.html'), name='mysite/signup_waiting'),
path('home/', include("home.urls")),
]
- home/urls.py
{SublimeText} home/urls.py
from django.contrib import admin
from django.urls import path
from home import views
urlpatterns = [
path('mysite/', views.welcome_home, name='mysite/welcome_home'),
]
- home/views.py
{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, 'mysite/signup_waiting.html', {'user':user})
return redirect('/mysite/')
return render(request, 'mysite/signup.html')
@login_required
def welcome_home(request):
return render(request, 'mysite/welcome_home.html')
- home/templates/mysite/welcome_home.html
{SublimeText} home/templates/mysite/welcome_home.html
{% extends 'mysite/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 -->
- templates/mysite/base.html
{SublimeText} templates/mysite/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 'mysite/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 'mysite/logout' %}"><input type="submit" value="{{ user.username }} (Logout)"></a>
{% else %}
<a href="{% url 'mysite/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 reserved.</p>
</div>
</div>
</body>
</html>
- templates/mysite/login.html
{SublimeText} templates/mysite/login.html
{% extends 'mysite/welcome.html' %}
{% block logform %}
<div id="s-content">
<h2>loginform</h2>
<div>
<form method="POST" class="post-form" action="{% url 'mysite/login' %}">
{% 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="password">Password</label><br>
<input type="password" name="password" id="password"
value="{{ form.password.value|default_if_none:'' }}">
</div>
<a href="{% url 'mysite/welcome_home' %}"><button type="submit">Login</button></a>
</form>
</div>
</div>
{% endblock %}
- templates/mysite/signup.html
{SublimeText} templates/mysite/signup.html
{% extends 'mysite/welcome.html' %}
{% block logform %}
<div id="s-content">
<h2>loginform</h2>
<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 'mysite/signup_waiting' %}"><button type="submit">Create</button></a>
</form>
</div>
</div>
{% endblock %}
- templates/mysite/signup_waiting.html
{SublimeText} templates/mysite/signup_waiting.html
{% extends 'mysite/welcome.html' %}
{% block logform %}
<div id="s-content">
<h3>{{ user.username }}님 반갑습니다~^^</h3>
<h3>{{ user.email }}로 관리자 승인 여부 확인 후 회신 예정입니다.</h3>
</div>
{% endblock %}
- templates/mysite/welcome.html
{SublimeText} templates/mysite/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 'mysite/welcome' %}"><img src="{% static 'img/logo_w_persona.png' %}" width="140" height="38"></a>
</div>
<div class="h-item">
<a href="{% url 'mysite/login' %}"><input type="submit" value="LogIn"></a>
<a href="{% url 'mysite/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">
{% block logform %}
{% endblock %}
</div>
</div>
<div id="footer">
<p>Copyright © PERSONA All rights reserved.</p>
</div>
</div>
</body>
</html>
'python > django_ERP2' 카테고리의 다른 글
(macOS)[python] django-erp : (3) persona-erp bootstrap customize (0) | 2021.11.15 |
---|---|
(macOS)[python] django-erp : templates 분리 (2) bstest layout 분리 (0) | 2021.11.15 |
(macOS)[python] django-erp : bootstrap 적용 (0) | 2021.11.05 |
(macOS)[python] django-erp : login, logout, signup, signup_waiting (0) | 2021.11.05 |
(macOS)[python] django-erp : app 생성 (0) | 2021.11.04 |
- Total
- Today
- Yesterday
- Raspberry Pi
- pyserial
- r
- Templates
- server
- CSV
- vscode
- 라즈베리파이
- analysis
- Model
- git
- ERP
- Python
- COVID-19
- github
- 코로나
- 자가격리
- Regression
- SSH
- 코로나19
- Django
- DAQ
- sublime text
- Pandas
- MacOS
- DS18B20
- arduino
- 확진
- raspberrypi
- template
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |