from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages
def register(request):
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Пользователь {username} был успешно создан!')
return redirect('blog-home')
else:
form = UserCreationForm()
return render(request, 'users/registration.html', {'form': form, 'title':'Регистрация пользователя'})
{% load static %}
<!DOCTYPE html>
<html lang="ru" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{title}}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="icon" href="{% static 'blog/img/favicon.ico'%}">
<link rel="stylesheet" href="{% static 'blog/css/main.css'%}">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-5">
<a class="navbar-brand" href="{% url 'blog-home' %}"><b>RuHealer</b></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample09" aria-controls="navbarsExample09" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExample09">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'blog-home' %}">Главная</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'blog-contacti' %}">Про нас</a>
</li>
</ul>
</div>
<div class="navbar-nav">
<a href="" class="btn btn-outline-secondary mr-2">Регистрация</a>
<a href="" class="btn btn-outline-secondary ">Войти</a>
</div>
</nav>
<main class="container">
<div class="row">
<div class="col-md-8">
{% if messages %}
{% for mess in messages %}
<div class="alert alert-success">
{{ mess }}
</div>
{% endfor %}
{% endif %}
{% block main_sections %}
{% endblock %}
</div>
<aside class="col-md-4">
<div class="p-3">
{% block aside_news_sections %}
{% endblock aside_news_sections %}
</div>
<div class="p-3">
<img src="" class="img-thumbnail mb-2">
<button class="btn btn-warning">Посмотреть</button>
</div>
</aside>
</div>
</main>
</body>
</html>