Showing
10 changed files
with
105 additions
and
4 deletions
@@ -62,7 +62,7 @@ ROOT_URLCONF = 'capacitacion.urls' | @@ -62,7 +62,7 @@ ROOT_URLCONF = 'capacitacion.urls' | ||
62 | TEMPLATES = [ | 62 | TEMPLATES = [ |
63 | { | 63 | { |
64 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', | 64 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
65 | - 'DIRS': [], | 65 | + 'DIRS': [BASE_DIR/'templates'], |
66 | 'APP_DIRS': True, | 66 | 'APP_DIRS': True, |
67 | 'OPTIONS': { | 67 | 'OPTIONS': { |
68 | 'context_processors': [ | 68 | 'context_processors': [ |
@@ -14,8 +14,10 @@ Including another URLconf | @@ -14,8 +14,10 @@ Including another URLconf | ||
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
15 | """ | 15 | """ |
16 | from django.contrib import admin | 16 | from django.contrib import admin |
17 | -from django.urls import path | 17 | +from django.urls import path, include |
18 | 18 | ||
19 | urlpatterns = [ | 19 | urlpatterns = [ |
20 | path('admin/', admin.site.urls), | 20 | path('admin/', admin.site.urls), |
21 | + path('persona/', include('persona.urls'), name='persona'), | ||
22 | + # path('persona/', include('organismo.urls'), name='persona') | ||
21 | ] | 23 | ] |
persona/forms.py
0 → 100644
persona/templates/persona/crear.html
0 → 100644
1 | +{% extends 'base.html' %} | ||
2 | +{% block titulo %} | ||
3 | + Creacion de Persona | ||
4 | +{% endblock %} | ||
5 | + | ||
6 | +{% block contenido %} | ||
7 | +<h1>Creacion de Persona</h1> | ||
8 | + | ||
9 | +<form method="POST"> | ||
10 | + {{ form }} | ||
11 | + {% csrf_token %} | ||
12 | + <input type="submit" value="Guardar"> | ||
13 | +</form> | ||
14 | + | ||
15 | + | ||
16 | +{% endblock %} |
1 | +{% extends 'base.html' %} | ||
2 | +{% block titulo %} | ||
3 | + Lista de Personas | ||
4 | +{% endblock %} | ||
5 | + | ||
6 | +{% block contenido %} | ||
7 | +<h1>Lista de Personas</h1> | ||
8 | +<table> | ||
9 | + <tr> | ||
10 | + <th>Nombre</th> | ||
11 | + <th>Documento</th> | ||
12 | + </tr> | ||
13 | + {% for persona in personas %} | ||
14 | + <tr> | ||
15 | + <td>{{persona}}</td> | ||
16 | + <td>{{persona.documento_identidad}}</td> | ||
17 | + </tr> | ||
18 | + {% endfor %} | ||
19 | +</table> | ||
20 | +{% endblock %} |
persona/urls.py
0 → 100644
1 | +from django.urls import path | ||
2 | + | ||
3 | +from persona.views import persona_lista, persona_detalle, PersonaCreateView | ||
4 | + | ||
5 | +urlpatterns = [ | ||
6 | + path('lista', persona_lista, name='persona-lista'), | ||
7 | + path('detalle/<int:pk>', persona_detalle, name='persona-detalle'), | ||
8 | + path('creacion', PersonaCreateView.as_view(), name='persona-creacion') | ||
9 | +] |
1 | -from django.shortcuts import render | 1 | +from django.contrib.auth.mixins import LoginRequiredMixin |
2 | +from django.shortcuts import render, get_object_or_404 | ||
2 | 3 | ||
3 | # Create your views here. | 4 | # Create your views here. |
5 | +from django.urls import reverse_lazy | ||
6 | +from django.views.generic import CreateView | ||
7 | + | ||
8 | +from persona.forms import PersonaForm | ||
9 | +from persona.models import Persona | ||
10 | + | ||
11 | + | ||
12 | +def persona_lista(request): | ||
13 | + personas = Persona.objects.all() | ||
14 | + return render(request, 'persona/lista_personas.html', {'personas': personas}) | ||
15 | + | ||
16 | + | ||
17 | +def persona_detalle(request, pk): | ||
18 | + persona = get_object_or_404(Persona, id=pk) | ||
19 | + return render(request, 'persona/detalle_persona.html', {'persona': persona}) | ||
20 | + | ||
21 | + | ||
22 | +class PersonaCreateView(LoginRequiredMixin, CreateView): | ||
23 | + model = Persona | ||
24 | + form_class = PersonaForm | ||
25 | + template_name = 'persona/crear.html' | ||
26 | + success_url = reverse_lazy('persona-lista') | ||
27 | + |
-
Please register or login to post a comment