Django: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
KKeine Bearbeitungszusammenfassung |
|||
| Zeile 2: | Zeile 2: | ||
=Django-Projekt anlegen= | =Django-Projekt anlegen= | ||
==Installation im entsprechenden Verzeichnis== | ==Installation im entsprechenden Verzeichnis== | ||
<ol style="list-style-type: decimal;"><li><p>python3 -m venv .venv</p></li><li><p>source .venv/bin/activate</p><pre>jetzt kann python.exe mit python aufgerufen werden | <ol style="list-style-type: decimal;"><li><p>python3 -m venv .venv</p></li><li><p>source .venv/bin/activate</p> | ||
<li><p>oder auch</p> | |||
<pre>jetzt kann python.exe mit python aufgerufen werden | |||
deactivate ==> das Enviroment wieder deaktivieren</pre></li><li><p>pip install django</p></li><li><p>python -m django –-version</p> | deactivate ==> das Enviroment wieder deaktivieren</pre></li><li><p>pip install django</p></li><li><p>python -m django –-version</p> | ||
<pre>ℹ nur zur Prüfung ob alles OK ist | <pre>ℹ nur zur Prüfung ob alles OK ist | ||
Version vom 21. September 2023, 12:24 Uhr
Django-Projekt anlegen
Installation im entsprechenden Verzeichnis
python3 -m venv .venv
source .venv/bin/activate
oder auch
jetzt kann python.exe mit python aufgerufen werden deactivate ==> das Enviroment wieder deaktivieren
pip install django
python -m django –-version
ℹ nur zur Prüfung ob alles OK ist oder auch mit python >>> import django >>> print(django.get_version())
Projekt anlegen
- django-admin startproject <projektname>
- python manage.py makemigrations polls
- python manage.py sqlmigrate polls 0001
- python manage.py check;
- python manage.py migrate
- python manage.py shell
ℹ nur zum üben
>>> from polls.models import Poll
>>> from polls.models import Choice
>>> Poll
>>> dir(Choice)
>>> Poll.slug
>>> Choice.objects.all()
>>> p = Poll(name="Wann steht ihr morgens immer auf?", slug="weckzeit")
>>> p.id
>>> p.save()
>>> Poll.objects.filter(slug="weckzeit").all()
>>> a = Poll.objects.get(slug="weckzeit")
>>> b = Poll.objects.get(pk=2)
>>> Choice.objects.all()[2]
>>> Choice.objects.all()[2].name
>>> quit()
>>> from polls.models import Choice, Poll
>>> a = Poll.objects.first()
>>> Choice.objects.filter(poll__id=1).all() oder besser >>> a.choice_set.all()
>>> python manage.py create_template_tags foobar
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username='Max') # Hohle den Benutzer Max aus der Datenbank
>>> u.set_password('neues passwort') # Vergebe das neue Passwort
>>> u.save() # Speichere das neue Passwort in der Datenbank
>>> from django.contrib.auth.models import User
>>> users = User.objects.all()
>>> users
>>> user = User.objects.create_user('Ernst', 'ernst@ernst.org', 'benutzer_passwort')
>>>
>>>
zurück zur ==> Hauptseite