reestructuracion del sitio

This commit is contained in:
jp.dev 2020-11-20 20:52:22 -03:00
parent 087b4f8fa6
commit 10f4ed8a37
25 changed files with 266 additions and 44 deletions

View File

@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'ProyectoWebApp',
'servicios',
]
MIDDLEWARE = [

View File

@ -21,4 +21,5 @@ from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('ProyectoWebApp.urls')),
path('servicios/', include('servicios.urls')),
]

View File

@ -0,0 +1,7 @@
from django.apps import AppConfig
class ProyectowebappConfig(AppConfig):
name = 'ProyectoWebApp'

View File

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@ -8,7 +8,7 @@
<link href="{% static 'ProyectoWebApp/vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<!-- Fonts -->
<!-- Link externo -->
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@300&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lora:400,400i,700,700i" rel="stylesheet">
@ -28,7 +28,7 @@
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark py-lg-4" id="mainNav">
<div class="container">
<a class="navbar-brand text-uppercase text-expanded font-weight-bold d-lg-none" href="{% url 'Inicio' %}">Gestión de Pedidos</a>
<a class="navbar-brand text-uppercase text-expanded font-weight-bold d-lg-none" href="{% url 'Inicio' %}">Esclavo del Juego</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@ -49,6 +49,7 @@
<li class="nav-item {% if request.path == '/blog' %}active{% endif %} px-lg-4">
<a class="nav-link text-uppercase text-expanded" href="{% url 'Blog' %}">Blog</a>
</li>
</ul>
</div>
</div>

View File

@ -14,7 +14,8 @@
<span class="section-heading-upper">Genialidad</span>
<span class="section-heading-lower">El mejor Jugador</span>
</h2>
<p class="mb-3">En la puertra de tu casa en menos de 48 h con el envío normal. En menos de 24 h con el envío express.
<p class="mb-3">..."Solo vi la oportunidad y la aproveché, así fue como me converti en el mejor jugador del mundo"...</p>
<p> -Iggins.</p>
</p>
</div>

View File

@ -1,10 +0,0 @@
{% extends 'ProyectoWebApp/base.html' %}
{% load static %}
{% block content %}
<div><p>Servicios</p></div>
{% endblock %}

View File

@ -1,17 +1,17 @@
from django.urls import path
from ProyectoWebApp import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.home, name="Inicio"),
path('servicios', views.servicios, name ='Servicios'),
path('tienda', views.tienda, name ='Tienda'),
path('blog', views.blog, name ='Blog'),
path('contacto', views.contacto, name='Contacto'),
path('sample/', views.sample, name ='Sample'),
]
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

View File

@ -2,9 +2,6 @@ from django.shortcuts import render, HttpResponse
def home(request):
return render(request, "ProyectoWebApp/home.html")
def servicios(request):
return render(request, "ProyectoWebApp/servicios.html")
def tienda(request):
return render(request, "ProyectoWebApp/tienda.html")
@ -18,4 +15,3 @@ def contacto(request):
def sample(request):
return render(request, "ProyectoWebApp/sample.html")

View File

@ -1,21 +1,173 @@
# 📚️ [Proyecto Web Completo](https://gitea.kickto.net/jp.av.dev/intro_Django/src/branch/master/ProyectoWeb)
**Ejémplo estructura común página web**
```
+---------------------------------------+
| +------+ +-------------------+ |
| | Logo | | Menu | |<---- cont. estatico y dinamico
| +------+ +-------------------+ |
| |
| |
| +-------------------------------+ |
| | | |
| | | |
| | Zona de Carga | |
| | | |
| | de Contenido | |<---- cont. estatico y dinamico
| | | |
| | | |
| | | |
| +-------------------------------+ |
| |
| +-------------------------------+ |
| | Pie de página | | <---- rrss, contacto
| +-------------------------------+ |
+---------------------------------------+
```
El contenido a mostar en la zona de carga dependerá
de lo seleccionado en menú o pie de página.
- Crear URLs y Vistas
- Crear Plantillas y herencias
- Manejar archivos externos
- Conf. panel de administración
- Conf. conexión a BBDD
- CRUD con BBDD
- Trabajo con formularios y envío de mails
- Depsliege
## Inicio ProyectoWeb
```
django-admin startproject ProyectoWeb
cd ProyectoWeb
python3 manage.py startapp ProyectoWebApp
# configuar settings.py (TimeZone, idioma, ip , mail, bd...)
python3 manage.py runserver 192.168.0.4:8000'
```
### Menu:
- Home
- Servicios
- Tienda
- Blog
- Contacto
- *(admin)*
App/
*views.py*
```
from django.shortcuts import render, HttpResponse
def home(request):
return HttpResponse("Inicio")
def servicios(request):
return HttpResponse("Servicios")
def tienda(request):
return HttpResponse("Tienda")
def blog(request):
return HttpResponse("Blog")
def contacto(request):
return HttpResponse("Contacto")
```
Project/*urls.py*
```
from django.contrib import admin
from django.urls import path
from ProyectoWebApp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name="Inicio"),
path('servicios/', views.servicios, name ='Servicios'),
path('tienda/', views.tienda, name ='Tienda'),
path('blog/', views.blog, name ='Blog'),
path('contacto/', views.contacto, name='Contacto'),
]
```
*Como es común un proyecto se compone de varias Apps*
*Y una App puede ser reutilizada en otro proyecto*
*urls.py explica como organizar urls para manejar multiples Apps*
### Organizar URLs
**Including another URLconf**
- 1. Import the include() function: *from django.urls import include, path*
- 2. Add a URL to urlpatterns: *path('blog/', include('blog.urls'))*
Project/*urls.py*
```
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('ProyectoWebApp/', include('ProyectoWebApp.urls')),
]
```
**Para evitar tener que escribir misitio.com/ProyectoWebApp/home**
**Dejar '' en vez de 'Proyec...' en el path de ProyectoWeb/urls.py**
### Crear urls.py en la carpeta de la aplicacion
*App/urls.py*
```
from django.urls import path
from ProyectoWebApp import views
urlpatterns = [
path('', views.home, name="Inicio"),
path('servicios/', views.servicios, name ='Servicios'),
path('tienda/', views.tienda, name ='Tienda'),
path('blog/', views.blog, name ='Blog'),
path('contacto/', views.contacto, name='Contacto'),
]
```
## Crear Templates
***ProyectoWebApp/templates/ProyectoWebApp/ por convención***
inicio - servicios - tienda - blog - contacto
### Registrar App
***Project/settings.py***
```
INSTALLED_APPS = [
...
'ProyectoWebApp',
]
```
### Modificar vistas para html
App/*views.py*
```
from django.shortcuts import render, HttpResponse
def home(request):
return render(request, "ProyectoWebApp/home.html")
def servicios(request):
return render(request, "ProyectoWebApp/servicios.html")
def tienda(request):
return render(request, "ProyectoWebApp/tienda.html")
def blog(request):
return render(request, "ProyectoWebApp/blog.html")
def contacto(request):
return render(request, "ProyectoWebApp/contacto.html")
```
## [Proyecto Web](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-proyecto-web)
- [Iniciar Proyecto Django](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-inicio-proyectoweb)
- [Creación Vistas](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-creaci%C3%B3n-de-las-vistas)
- [Registro de URLs](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-registro-de-urls)
- [Organizar URLs por App](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-organizar-urls-por-app)
- [Crear Templates](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-crear-templates)
- [Restrar App](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-registrar-app)
- [Registro Vistas html](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7a_Proyecto_Web_Completo#user-content-modificar-vistas-para-html)
## [Bootstrap y Herencia en la estructura del sitio](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo)
- [Formato del sitio con Bootstrap](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-dar-formato-al-sitio-con-bootstrap)
- [TAG {% load static %}](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-tag-load-static)
- [Herencia de Plantillas](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-herencia-de-plantillas-y-estructura-del-sitio)
- [Creación de plantilla base](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-creaci%C3%B3n-plantilla-base)
- [Barra de navegación, destacar sitio en visita](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-barra-de-navegacion-destacar-sitio-en-visita)
- [Creación App servicios](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-creacion-de-otra-app)
- [ORM Creación modelo](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-orm-object-relational-mapping)
- [Pillow, almacenar imagenes](https://gitea.kickto.net/jp.av.dev/intro_Django/wiki/7b_Proyecto_Web_Completo#user-content-para-usar-imagenes)

22
ProyectoWeb/manage.py Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ProyectoWeb.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,22 @@
# Generated by Django 3.1.3 on 2020-11-20 18:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('servicios', '0007_auto_20201119_0323'),
]
operations = [
migrations.AlterModelOptions(
name='servicio',
options={'verbose_name': 'servicio', 'verbose_name_plural': 'servicios'},
),
migrations.AlterField(
model_name='servicio',
name='imagen',
field=models.ImageField(upload_to='servicios'),
),
]

View File

@ -5,10 +5,10 @@ from django.db import models
class Servicio(models.Model):
titulo = models.CharField( max_length = 50 )
contenido = models.CharField( max_length = 50 )
imagen = models.ImageField(upload_to = 'servicios')
imagen = models.ImageField( upload_to= 'servicios' )
created = models.DateTimeField( auto_now_add = True)
updated = models.DateTimeField( auto_now_add = True)
class Meta:
verbose_name = 'servicio'
verbose_name_plural = 'servicios'
@ -17,5 +17,3 @@ class Servicio(models.Model):
def __str__(self):
return self.titulo

View File

@ -0,0 +1,18 @@
{% extends 'ProyectoWebApp/base.html' %}
{% load static %}
{% block content %}
{% for servicio in servicios %}
<div><p>
<h2 style="color: white;">{{servicio.titulo}}</h2>
<p style="color: lightgray;">{{servicio.contenido}}</p>
<p><img src="{{servicio.imagen.url}}"></p>
</p></div>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,11 @@
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.servicios, name ='Servicios'),
]
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

View File

@ -1,3 +1,8 @@
from django.shortcuts import render
from servicios.models import Servicio
# Create your views here.
def servicios(request):
servicios = Servicio.objects.all()
return render(request, "servicios/servicios.html", {"servicios":servicios})