Django: Unterschied zwischen den Versionen

Aus AstroNeth-Wiki
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt: „=Django-Projekt anlegen= ==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 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 oder auch mit python >>> import django >>…“
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
[Django Website](https://www.djangoproject.com/)
=Django-Projekt anlegen=
=Django-Projekt anlegen=
==Installation im entsprechenden Verzeichnis==
==Installation im entsprechenden Verzeichnis==

Version vom 9. Februar 2023, 17:45 Uhr

[Django Website](https://www.djangoproject.com/)

Django-Projekt anlegen

Installation im entsprechenden Verzeichnis

  1. python3 -m venv .venv

  2. source .venv/bin/activate

    jetzt kann python.exe mit python aufgerufen werden
    deactivate ==> das Enviroment wieder deaktivieren
  3. pip install django

  4. python -m django –-version

    ℹ nur zur Prüfung ob alles OK ist
    oder auch mit
    python
    >>> import django
    >>> print(django.get_version())
    

Projekt anlegen

  1. django-admin startproject <projektname>
    • python manage.py makemigrations polls
    • python manage.py sqlmigrate polls 0001
    • python manage.py check;
  2. python manage.py migrate
  3. 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()


zurück zur ==> Hauptseite