User Tools

Site Tools


informatica:linux:django

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
informatica:linux:django [2014/03/18 15:46] – [LDAP] javiinformatica:linux:django [2019/05/19 16:55] – [Activar la interfaz administrativa] javi
Line 2: Line 2:
  
 django python framework django python framework
 +
 +===== Instalacion =====
 +
 +1. Instalar pip
 +
 +  sudo aptitude update; sudo aptitude install python-pip
 +  
 +2. Instalar ultima version de django:
 +
 +  sudo pip install Django==1.8
  
 ===== Primeros pasos ===== ===== Primeros pasos =====
Line 91: Line 101:
   python manage.py runserver 0.0.0.0:8080   python manage.py runserver 0.0.0.0:8080
  
-===== Activar la interfaz administrativa =====+===== Interfaz administrativa ===== 
 + 
 +Ahora la interfaz administrativa se activa por defecto 
 + 
 +==== Crear superusuario ==== 
 + 
 +https://docs.djangoproject.com/en/2.2/ref/django-admin/#django-admin-createsuperuser 
 + 
 +==== (Deprecated) Activar la interfaz administrativa =====
  
 1 1
Line 332: Line 350:
   Tabla1.objects.filter(pub_date__year=2006)   Tabla1.objects.filter(pub_date__year=2006)
      
-===== Instalacion manual ===== 
- 
-1. Download the latest release from our download page. 
- 
-2. Untar the downloaded file (e.g. tar xzvf Django-X.Y.tar.gz, where X.Y is the version number of the latest release). If you're using Windows, you can download the command-line tool bsdtar to do this, or you can use a GUI-based tool such as 7-zip. 
- 
-3. Change into the directory created in step 2 (e.g. cd Django-X.Y). 
- 
-4. If you're using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup.py install at the shell prompt. If you're using Windows, start a command shell with administrator privileges and run the command python setup.py install. This will install Django in your Python installation's site-packages directory. 
- 
-  python setup.py install 
- 
 ===== Ejemplo aplicacion sin BBDD ===== ===== Ejemplo aplicacion sin BBDD =====
  
Line 509: Line 515:
 } }
 ... ...
 +</code>
 +
 +Flujo habitual para mantener el modelo:
 +
 +<code>
 +1. Change your models (in **models.py**).
 +2. Run **python manage.py makemigrations** to create migrations for those changes
 +3. Run **python manage.py migrate** to apply those changes to the database.
 </code> </code>
  
Line 811: Line 825:
  
 <code> <code>
 +from django.contrib.auth import authenticate
 +
 def login(request): def login(request):
     ''' Displays/process login form'''     ''' Displays/process login form'''
Line 840: Line 856:
  
 Falta el template y el resto de la vista. Es solo un ejemplo Falta el template y el resto de la vista. Es solo un ejemplo
 +
 +===== Errores =====
 +
 +==== The password is too similar to the username. ====
 +
 +En realidad no es un error, es solo para documentar un atajo para evitar esta restricción a la hora de especificar una contraseña para un nuevo usuario desde la interfaz gráfica del módulo admin.
 +
 +https://stackoverflow.com/a/35330167
 +
 +1. Crear el usuario desde el admin:
 +
 +http://localhost:8000/admin/auth/user/add/
 +
 +2. Iniciar shell
 +
 +  cd /path/django && python manage.py shell
 +  
 +3. Cambiar la contraseña de ese usuario, en este ejemplo "your_user":
 +
 +<code>
 +from django.contrib.auth.models import User
 +user = User.objects.get(username='your_user')
 +user.set_password('simple')
 +user.save()
 +</code>
 +
 +====  Error al crear app ====
 +
 +Comando:
 +
 +<code>
 +python manage.py startapp app1
 +</code>
 +
 +Error:
 +
 +<code>
 +  File "manage.py", line 16
 +    ) from exc
 +         ^
 +SyntaxError: invalid syntax
 +</code>
 +
 +Solución:
 +
 +<code>
 +python3 manage.py startapp app1
 +</code>
informatica/linux/django.txt · Last modified: 2019/05/19 16:55 by javi