Django Project With Bootstrap Database-URL-Views-Bootstrap Template-Security
My site adlı proje oluştukmak için: django-admin startproject mysite
Poll adında bir app eklemek için: python manage.py startapp polls Uygulamayı çalıştırmak için mysite içerisine gidip: python manage.py runserver Model eklendikten sonra polls app i için : python manage.py makemigrations polls mysite içerisindeki settings.py içerisine INSTALLED_APPS Altına ‘polls’, ifadesi eklenir. Bu işlemden sonra 1-)python manage.py makemigrations polls 2-)python manage.py migrate komutu çalıştırılır. Migrations dosyası içerisinde initial.py adlı file oluşur. Bu file içerisinde oluşturduğunuz modeller gözükür.
POPULATING DATABASE:
- python manage.py Shell
-
import django
-
django.setup()
-
from polls.models import Question,Choice
- Question.objects.all()
- from django.utils import timezone
-
q=Question(question_text="whats your name",pub_date=timezone.now())
-
q.save()
-
Question.objects.all()
- exit()
Models.py içerisine def str(self): return self.choice_text
modeller içerisindeki değerleri döndüren metod yazılır. Choice_text bi attributre tır.
python manage.py createsuperuser //süper user oluşturma python manage.py runserver