Django: Unterschied zwischen den Versionen

Aus AstroNeth-Wiki
Zur Navigation springen Zur Suche springen
KKeine Bearbeitungszusammenfassung
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
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>
<ol style="list-style-type: decimal;"><li><p>python3 -m venv .venv</p><p>oder</p><p>virtualenv .env</p></li><li><p>source .venv/bin/activate</p>
<li><p>oder auch</p><p>pipenv --python 3.11.0</p><p>pipenv shell</p><p>pipenv graph</p>
<li><p>oder besser</p><p>pipenv --python 3.11.0</p><p>pipenv shell</p><p>pipenv graph</p>
<pre>jetzt kann python.exe mit python aufgerufen werden
<pre>jetzt kann python.exe mit python aufgerufen werden
deactivate ==&gt; das Enviroment wieder deaktivieren</pre></li><li><p>pip install django</p></li><li><p>python -m django –-version</p>
deactivate ==&gt; das Enviroment wieder deaktivieren</pre></li><li><p>pipenv 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
Zeile 13: Zeile 13:
>>> print(django.get_version())
>>> print(django.get_version())
</pre></li>
</pre></li>
<li><p>pip install mysqlclient</p>
<li><p>pipenv install mysqlclient</p>
<li><p>pipenv install django-debug-toolbar</p>
</ol>
</ol>



Aktuelle Version vom 14. Oktober 2024, 20:38 Uhr

Django Website

Django-Projekt anlegen

Installation im entsprechenden Verzeichnis

  1. python3 -m venv .venv

    oder

    virtualenv .env

  2. source .venv/bin/activate

  3. oder besser

    pipenv --python 3.11.0

    pipenv shell

    pipenv graph

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

  5. python -m django –-version

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

  7. pipenv install django-debug-toolbar

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()
      >>> 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