Proyecto1/Proyecto1

This commit is contained in:
jp.av.dev 2020-11-12 03:17:08 -03:00
parent 5eebaa8665
commit ab8b2f3025
5 changed files with 220 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,16 @@
"""
ASGI config for Proyecto1 project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Proyecto1.settings')
application = get_asgi_application()

View File

@ -0,0 +1,120 @@
"""
Django settings for Proyecto1 project.
Generated by 'django-admin startproject' using Django 3.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3w9g54jr$hiee5djh&8nhk2z57tt*&@noli^nj44_9#z6h3z&5'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['localhost','192.168.31.30','192.168.0.3','192.168.0.4']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'Proyecto1.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/home/rat/weblocal/PildorasInf/Proyecto1/Proyecto1/plantillas'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'Proyecto1.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Santiago'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'

View File

@ -0,0 +1,30 @@
"""Proyecto1 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
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'))
"""
from django.contrib import admin
from django.urls import path
from Proyecto1.views import primeravista, otra, verFecha, calcEdad, herencia1, herencia2
urlpatterns = [
path('admin/', admin.site.urls),
path('primera/', primeravista),
path('mas/', otra),
path('fecha/', verFecha),
path('edades/<int:edad>/<int:ano>', calcEdad),
path('hija1/', herencia1),
path('hija2/', herencia2),
]

View File

@ -0,0 +1,54 @@
from django.http import HttpResponse
from django.template import Template, Context
from django.template.loader import get_template
from django.shortcuts import render
import datetime
class Persona(object):
def __init__(self, nombre, apellido):
self.nombre = nombre
self.apell = apellido
def primeravista(request):
p1 = Persona("Zerafín", "Menendes")
fecha = datetime.datetime.now()
#doc_externo = open("/home/rat/weblocal/PildorasInf/Proyecto1/Proyecto1/plantillas/miplantilla.html", 'r')
#plantilla = Template(doc_externo.read())
#doc_externo.close()
#plantilla = get_template('miplantilla.html')
temas_curso = ["Vistas", "Modelos", "Plantillas", "Formularios", "Despliege"]
#ctx = Context({"nombre_persona":p1.nombre, "apell_persona":p1.apell, "fecha":fecha, "temas":temas_curso})
#documento = plantilla.render({"nombre_persona":p1.nombre, "apell_persona":p1.apell, "fecha":fecha, "temas":temas_curso})
#return HttpResponse(documento)
return render(request, "miplantilla.html", {"nombre_persona":p1.nombre, "apell_persona":p1.apell, "fecha":fecha, "temas":temas_curso})
def herencia1(request):
fecha_ahora = datetime.datetime.now()
return render(request, "childpage1.html", {"verFecha":fecha_ahora})
def herencia2(request):
fecha_ahora = datetime.datetime.now()
return render(request, "childpage2.html", {"verFecha":fecha_ahora})
def otra(request):
return HttpResponse("Otra vista ( ̄▽ ̄)con Django")
def verFecha(request):
fecha_ahora = datetime.datetime.now()
documento = "<html><body><h3> Hora y Fecha actual: %s</h3></body></html>" % fecha_ahora
return HttpResponse(documento)
def calcEdad(request, edad, ano):
periodo = ano - 2020
edadfutura = edad + periodo
doc = "<html><body><h3>En el %s tendrás %s años</h3></body></html>" %(ano, edadfutura)
return HttpResponse(doc)