sexta parte 2
This commit is contained in:
0
accounts/__init__.py
Normal file
0
accounts/__init__.py
Normal file
3
accounts/admin.py
Normal file
3
accounts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
14
accounts/forms.py
Normal file
14
accounts/forms.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.contrib.auth.forms import get_user_model
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
class AccountSignUpForm(forms.ModelForm):
|
||||||
|
password = forms.CharField(max_length=20,label='Senha',widget=forms.PasswordInput)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ['username', 'email', 'password']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
0
accounts/migrations/__init__.py
Normal file
0
accounts/migrations/__init__.py
Normal file
3
accounts/models.py
Normal file
3
accounts/models.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
3
accounts/tests.py
Normal file
3
accounts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
4
accounts/urls.py
Normal file
4
accounts/urls.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from accounts.views import AccountCreateView
|
||||||
|
|
||||||
|
urlpatterns = [ path('accounts/signup/', AccountCreateView.as_view(), name='signup')]
|
||||||
24
accounts/views.py
Normal file
24
accounts/views.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
from django.views.generic.edit import CreateView
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.contrib.auth.hashers import make_password
|
||||||
|
from django.contrib.auth.forms import get_user_model
|
||||||
|
from django.contrib import messages
|
||||||
|
from accounts.forms import AccountSignUpForm
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
class AccountCreateView(CreateView):
|
||||||
|
model = User
|
||||||
|
form_class = AccountSignUpForm
|
||||||
|
template_name = 'registration/signup_from.html'
|
||||||
|
form_class = AccountSignUpForm
|
||||||
|
success_url = reverse_lazy('login')
|
||||||
|
sucess_message = 'Conta criada com sucesso!'
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.password = make_password(form.cleaned_data['password'])
|
||||||
|
form.save()
|
||||||
|
messages.success(self.request, 'Conta criada com sucesso!')
|
||||||
|
return super(AccountCreateView, self).form_valid(form)
|
||||||
|
|
||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,7 @@ from django.urls import path
|
|||||||
from polls import views
|
from polls import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('index', views.index, name='index'),
|
path('', views.index, name='home'),
|
||||||
path('ola', views.ola, name='ola')
|
path('index/', views.index, name='index'),
|
||||||
|
path('ola/', views.ola, name='ola'),
|
||||||
]
|
]
|
||||||
@@ -1,65 +1,65 @@
|
|||||||
{# Curso Django Framework do Zero: https://www.youtube.com/playlist?list=PLFOqHo8oIjzewcT23HCxJV0xWO451CTJe #}
|
{% extends '_base.html' %} <!-- herda tudo que já tem em _base.html -->
|
||||||
{% extends '_base.html' %} {# herda tudo que já tem em _base.html #}
|
{% load static %}
|
||||||
{% load static %} {# carrega o módulo static para fornecer arquivos estáticos #}
|
<!--
|
||||||
|
cada bloco abaixo como o mesmo nome terá o conteúdo
|
||||||
{#
|
substituído em _base.html, se não existir aqui, permanecerá
|
||||||
cada bloco abaixo como o mesmo nome terá o conteúdo
|
com o mesmo conteúdo original herdado de _base.html
|
||||||
substituído em _base.html, se não existir aqui, permanecerá
|
-->
|
||||||
com o mesmo conteúdo original herdado de _base.html
|
{% block head_title %}
|
||||||
#}
|
Django Framework
|
||||||
{% block head_title %}
|
|
||||||
Django Framework
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{# Bootstrap CSS #}
|
<!-- Bootstrap CSS -->
|
||||||
<link
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
||||||
rel="stylesheet"
|
<!-- CSS do Projeto-->
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
|
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
||||||
|
|
||||||
{# CSS do Projeto #}
|
|
||||||
{# o comando "static" traduz para o caminho correto para os arquivos estáticos #}
|
|
||||||
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<div class="container">
|
<main role="main">
|
||||||
<header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom">
|
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3
|
||||||
<a href="{% url 'index' %}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none">
|
bg-white border-bottom shadow-sm">
|
||||||
<span class="fs-4">Django do Zero</span>
|
<h5 class="my-0 mr-md-auto font-weight-normal">
|
||||||
</a>
|
<a href="{% url 'index' %}">Django</a>
|
||||||
<ul class="nav nav-pills">
|
</h5>
|
||||||
<li class="nav-item">
|
<a class="p-2 text-dark" href="{% url 'polls_all' %}">Perguntas</a>
|
||||||
<a href="{% url 'ola' %}" class="nav-link px-2 link-dark">Sobre</a>
|
<a class="p-2 text-dark" href="{% url 'about_page' %}">Sobre</a>
|
||||||
</li>
|
{% if user.is_authenticated %}
|
||||||
</ul>
|
<a class="p-2 text-dark" href="{% url 'account_edit' pk=user.pk %}">Minha conta</a>
|
||||||
</header>
|
<a class="p-2 text-dark" href="{% url 'logout' %}">Sair</a>
|
||||||
</div>
|
{% else %}
|
||||||
|
<a class="p-2 text-dark" href="{% url 'signup' %}">Cadastrar</a>
|
||||||
|
<a class="p-2 text-dark" href="{% url 'login' %}">Acessar</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% block content %}
|
{% include 'messages.html' %}
|
||||||
<p>Conteúdo padrão...</p>
|
{% block content %}
|
||||||
|
<p>Conteúdo padrão...</p>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<span class="text-muted">Rodapé...</span>
|
<span class="text-muted">Rodapé...</span>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
{# Bootstrap JavaScript #}
|
<!-- Bootstrap JavaScript -->
|
||||||
<script
|
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
|
||||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js">
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
|
||||||
</script>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
{# JS do Projeto #}
|
<!-- JS do Projeto -->
|
||||||
<script src="{% static 'js/base.js' %}"></script>
|
<script src="{% static 'js/base.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
/<div>
|
/<div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf taken %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
</form>
|
</form>
|
||||||
<button type="submit" class="btn btn-success ">Enviar</button>
|
<button type="submit" class="btn btn-success ">Enviar</button>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'polls.apps.PollsConfig',
|
'polls.apps.PollsConfig',
|
||||||
|
'accounts.apps.AccountsConfig',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -120,3 +121,7 @@ STATIC_URL = 'static/'
|
|||||||
|
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'public/static')
|
STATIC_ROOT = os.path.join(BASE_DIR, 'public/static')
|
||||||
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
|
||||||
|
|
||||||
|
LOGIN_REDIRECT_URL = '/ola'
|
||||||
|
LOGIN_REDIRECT_URL = '/ola'
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ from django.urls import path, include
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('', include('polls.urls')),
|
path('', include('polls.urls')),
|
||||||
|
path('', include('accounts.urls')),
|
||||||
|
path('accounts/', include('django.contrib.auth.urls'))
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user