Pythonescoool
Pythonescoool
Pythonescoool
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>
</body>
</html>
Aplicaciones/Academica
Toca a la carpeta Academica para crear un archivo urls.py
urls.py vacio
urlpatterns = [
path('', views.home)
]
views.py : Modelo Cliente-Servidor Explicado
def home(request):
return render(request, "Curso.html")
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('Aplicaciones.Academica.urls'))
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
def home(request):
Listadosestudiantes = Estudiante.objects.all()
___________________________________________________________________________________
_______________________________________________________
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>
<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>
<!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>
<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 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="card">
<div class="card-body">
<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>
<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>
{% 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">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
</head>
<body>
<span class="navbar-toggler-icon"></span>
</button>
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contacto</a>
</li>
</ul>
</div>
</nav>
{% 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>
</body>
</html>
urls.py vacio
urlpatterns = [
path('', views.home),
path('agregarCurso/', views.agregarCurso)
views.py
def home(request):
Listadosestudiantes = Estudiante.objects.all()
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('/')
return redirect('/')
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()
return redirect('/')
{% 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 %}
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)