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
|
||||
|
||||
urlpatterns = [
|
||||
path('index', views.index, name='index'),
|
||||
path('ola', views.ola, name='ola')
|
||||
path('', views.index, name='home'),
|
||||
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 #}
|
||||
{% 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á
|
||||
com o mesmo conteúdo original herdado de _base.html
|
||||
#}
|
||||
{% block head_title %}
|
||||
Django Framework
|
||||
{% extends '_base.html' %} <!-- herda tudo que já tem em _base.html -->
|
||||
{% load static %}
|
||||
<!--
|
||||
cada bloco abaixo como o mesmo nome terá o conteúdo
|
||||
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
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{# Bootstrap CSS #}
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.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' %}">
|
||||
{% block css %}
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
||||
<!-- CSS do Projeto-->
|
||||
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block header %}
|
||||
<div class="container">
|
||||
<header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom">
|
||||
<a href="{% url 'index' %}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none">
|
||||
<span class="fs-4">Django do Zero</span>
|
||||
</a>
|
||||
<ul class="nav nav-pills">
|
||||
<li class="nav-item">
|
||||
<a href="{% url 'ola' %}" class="nav-link px-2 link-dark">Sobre</a>
|
||||
</li>
|
||||
</ul>
|
||||
</header>
|
||||
</div>
|
||||
<main role="main">
|
||||
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3
|
||||
bg-white border-bottom shadow-sm">
|
||||
<h5 class="my-0 mr-md-auto font-weight-normal">
|
||||
<a href="{% url 'index' %}">Django</a>
|
||||
</h5>
|
||||
<a class="p-2 text-dark" href="{% url 'polls_all' %}">Perguntas</a>
|
||||
<a class="p-2 text-dark" href="{% url 'about_page' %}">Sobre</a>
|
||||
{% if user.is_authenticated %}
|
||||
<a class="p-2 text-dark" href="{% url 'account_edit' pk=user.pk %}">Minha conta</a>
|
||||
<a class="p-2 text-dark" href="{% url 'logout' %}">Sair</a>
|
||||
{% 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 %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
<p>Conteúdo padrão...</p>
|
||||
<div class="container">
|
||||
{% include 'messages.html' %}
|
||||
{% block content %}
|
||||
<p>Conteúdo padrão...</p>
|
||||
{% endblock content %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
<footer class="footer">
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<span class="text-muted">Rodapé...</span>
|
||||
</div>
|
||||
</footer>
|
||||
</footer>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
{# Bootstrap JavaScript #}
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js">
|
||||
</script>
|
||||
<!-- Bootstrap JavaScript -->
|
||||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
||||
|
||||
{# JS do Projeto #}
|
||||
<script src="{% static 'js/base.js' %}"></script>
|
||||
<!-- JS do Projeto -->
|
||||
<script src="{% static 'js/base.js' %}"></script>
|
||||
{% endblock %}
|
||||
@@ -7,7 +7,7 @@
|
||||
/<div>
|
||||
<div class="card-body">
|
||||
<form method="post">
|
||||
{% csrf taken %}
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</form>
|
||||
<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.staticfiles',
|
||||
'polls.apps.PollsConfig',
|
||||
'accounts.apps.AccountsConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -120,3 +121,7 @@ STATIC_URL = 'static/'
|
||||
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'public/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 = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('polls.urls')),
|
||||
path('', include('accounts.urls')),
|
||||
path('accounts/', include('django.contrib.auth.urls'))
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user