Pythonescoool

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 19

2 Paso

Aplicaciones/ Academica

Toca a la carpeta Academica para crear una nueva carpeta llamada Templates

Curso.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<h1>Estas en la pagina de Curso </h1>

</body>
</html>

Aplicaciones/Academica
Toca a la carpeta Academica para crear un archivo urls.py

urls.py vacio

from django.urls import path


from . import views

urlpatterns = [
path('', views.home)

]
views.py : Modelo Cliente-Servidor Explicado

from django.shortcuts import render

# Create your views here.

def home(request):
return render(request, "Curso.html")

segundo archivo : urls.py

from django.contrib import admin


from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('Aplicaciones.Academica.urls'))

Run on it : python manage.py runserver 8080

-----------------------------------------------------------------------------------
---------------------------------------------------------------------

views.py : Modelo Cliente-Servidor Explicado

from django.shortcuts import render


from .models import Estudiante

# Create your views here.

def home(request):
Listadosestudiantes = Estudiante.objects.all()

return render(request, "Curso.html", {"estudiantes": Listadosestudiantes})

___________________________________________________________________________________
_______________________________________________________

Curso.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"

integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">

</head>
<body>

<h1>Estas en la pagina de Curso </h1>

<ul>

{% for e in estudiantes %}
<li>{{e.nombre}}</li>

{% endfor %}

</ul>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous">
</script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous">
</script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous">
</script>

</body>
</html>

Curso.html : Copia y elimina el codigo

Pega el codigo en un archivo navigacion.html

------------------------------crear un nuevo archivo


navigacion.html-----------------------------

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"

integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">

</head>
<body>

<h1>Estas en la pagina de Curso </h1>

<ul>

{% for e in estudiantes %}
<li>{{e.nombre}}</li>

{% endfor %}

</ul>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous">
</script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous">
</script>

</body>
</html>

_________________Curso.html importante__________________________________________

{% extends "./navigacion.html" %}

{% block title %} Gestión de Cursos {% endblock %}

{% block body %}

<div class="row">
<div class="col-sm-10 col-md-6 col-lg-4 col-xl-3">

{% if messages %}
{% for message in messages %}

<div class="alert alert-dismissible alert-success">


<button type="button" class="close"
data-dismiss="alert">&times;</button>
<strong class="text-dark">{{ message }}</strong>
</div>
{% endfor %}
{% endif %}

<h2 style="text-align: center;">Curso de Python</h2>

<div class="card">

<div class="card-body">

<form action="/registrarCurso/" method="POST">{% csrf_token %}

<div class="form-group">
<input type="text" id="txtCodigo" name="txtCodigo"
class="form-control" placeholder="Código"
minlength="6" maxlength="6" required>
</div>

<div class="form-group">
<input type="text" id="txtNombre" name="txtNombre"
class="form-control" placeholder="Nombre"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtMateria" name="txtMateria"
class="form-control" placeholder="Materia"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtNota" name="txtNota" class="form-
control" min="1" max="9"
value="1" required>
</div>

<div class="form-group">
<input type="text" id="txtJornada" name="txtJornada"
class="form-control" placeholder="Jornada"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtEstado" name="txtEstado"
class="form-control" placeholder="Estado"
maxlength="50" required>
</div>

<div class="form-group">
<button type="submit" class="btn btn-danger btn-block text-
white">Guardar</button>
</div>
</form>
</div>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-8 col-xl-9">


<h1 style="text-align: center;">Lista de Estudiantes</h1>
<div class="table-responsive py-1">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Código</th>
<th>Nombre</th>
<th>Materia</th>
<th>Nota</th>
<th>Jornada</th>
<th>Estado</th>

<th colspan="">Opciones</th>
<th colspan="">Opciones</th>
</tr>
</thead>
<tbody>

{% for e in estudiantes %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{e.codigo}}</td>
<td>{{e.nombre}}</td>
<td>{{e.materia}}</td>
<td>{{e.nota}}</td>
<td>{{e.jornada}}</td>
<td>{{e.estado}}</td>

<td><a href="edicion_Curso/{{e.codigo}}" class="btn btn-


warning">Editar</a></td>
<td><a href="eliminar_Curso/{{e.codigo}}" class="btn btn-
danger btnEliminacion">Eliminar</a></td>
</tr>

{% endfor %}

</tbody>
</table>
</div>
</div>
</div>

{% endblock %}

-------navigacion.html importante
-----------------------------------------------------------------------------------
--------------------

<!DOCTYPE html>
<html lang="en">

<head>
{% load static %}

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>{% block title %} {% endblock %}</title>

<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"

integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">

<link rel="stylesheet" href="{% static 'css/gestionCursos.css' %}">

</head>

<body>

<nav class="navbar navbar-expand-lg navbar-light bg-warning">

<a class="navbar-brand" href="#">Universidad</a>

<button class="navbar-toggler" type="button" data-toggle="collapse" data-


target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle
navigation">

<span class="navbar-toggler-icon"></span>

</button>

<div class="collapse navbar-collapse" id="navbarNav">

<ul class="navbar-nav">

<li class="nav-item">

<a class="nav-link" href="#">Home <span class="sr-


only">(current)</span></a>

</li>

<li class="nav-item">
<a class="nav-link" href="#">Contacto</a>
</li>

</ul>

</div>

</nav>

<div class="container py-4">

{% block body %}
{% endblock %}

</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"

integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous">
</script>

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"

integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous">
</script>

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"

integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous">
</script>

<script src="{% static 'js/gestionCursos.js' %}"></script>

</body>
</html>

urls.py vacio

from django.urls import path


from . import views

urlpatterns = [
path('', views.home),
path('agregarCurso/', views.agregarCurso)

views.py

from django.shortcuts import render, redirect


from .models import Estudiante
from django.contrib import messages

# Create your views here.

def home(request):
Listadosestudiantes = Estudiante.objects.all()

return render(request, "Curso.html", {"estudiantes": Listadosestudiantes})

def agregarCurso(request):
codigo = request.POST['txtCodigo']
nombre = request.POST['txtNombre']
materia = request.POST['txtMateria']
nota = request.POST['txtNota']
jornada = request.POST['txtJornada']
estado = request.POST['txtEstado']

curso = Estudiante.objects.create(
codigo=codigo, nombre=nombre, materia=materia, nota=nota, jornada=jornada,
estado=estado)
messages.success(request, '¡Curso registrado!')
return redirect('/')

def eliminar_Curso(request, codigo):


curso = Estudiante.objects.get(codigo=codigo)
curso.delete()

messages.success(request, '¡Curso eliminado!')

return redirect('/')

def edicion_Curso(request, codigo):


curso = Estudiante.objects.get(codigo=codigo)
return render(request, "edicion_Curso.html", {"curso": curso})

def editar_Curso(request):
codigo = request.POST['txtCodigo']
nombre = request.POST['txtNombre']
materia = request.POST['txtMateria']
nota = request.POST['txtNota']
jornada = request.POST['txtJornada']
estado = request.POST['txtEstado']

curso = Estudiante.objects.get(codigo=codigo)
curso.nombre = nombre
curso.materia = materia
curso.nota = nota
curso.jornada = jornada
curso.estado = estado
curso.save()

messages.success(request, '¡Curso actualizado!')

return redirect('/')

__________________crear un archivo edicion_Curso.html_____________________


{% extends "./navigacion.html" %}

{% block title %} Gestión de Cursos {% endblock %}

{% block body %}

<div class="row">
<div class="col-md-4 offset-md-4">

<h2>Edición de Curso</h2>

<div class="card">
<div class="card-body">
<form action="/editar_Curso/" method="POST">{% csrf_token %}
<div class="form-group">
<input type="text" id="txtCodigo" name="txtCodigo"
value="{{curso.codigo}}" class="form-control" placeholder="Código"
minlength="6" maxlength="6" readonly required>
</div>

<div class="form-group">
<input type="text" id="txtNombre" name="txtNombre"
value="{{curso.nombre}}" class="form-control" placeholder="Nombre"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtMateria" name="txtMateria"
value="{{curso.materia}}" class="form-control" placeholder="Materia"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtNota" name="txtNota"
value="{{curso.nota}}" class="form-control" min="1" max="9"
value="1" required>
</div>

<div class="form-group">
<input type="text" id="txtJornada" name="txtJornada"
value="{{curso.jornada}}" class="form-control" placeholder="Jornada"
maxlength="50" required>
</div>

<div class="form-group">
<input type="text" id="txtEstado" name="txtEstado"
value="{{curso.estado}}" class="form-control" placeholder="Estado"
maxlength="50" required>
</div>

<div class="form-group">
<button type="submit" class="btn btn-success btn-block
text-white">Actualizar</button>
</div>
</form>
</div>
</div>
</div>
</div>

{% endblock %}

_________________segundo archivo : urls.py ______________________________

from django.urls import path


from . import views

urlpatterns = [
path('', views.home),
path('agregarCurso/', views.agregarCurso),
path('edicion_Curso/<codigo>', views.edicion_Curso),
path('editar_Curso/', views.editar_Curso),
path('eliminar_Curso/<codigo>', views.eliminar_Curso)

You might also like