Django/ Python! Flashcards
What is admin.py?
admin.py is used to is used to register created models to the admin interface.
How do you create a new project in Django?
django-admin startproject name .
Don’t forget the period!
How do you create a new app in django?
python manage.py startapp (name you create)
How do you add an app to your project?
You visit the settings.py file and add it to the installed apps list(array). Then, update url patterns in urls.py to include your apps urls.
Each class in your models represents a?
a table in your database
Each variable in you class represents?
a column of your table
how can you create a model (title, return)
class Post(models.Model):
title = models.Charfield(max_length=140)
def __str__(self):
return self.title
how do we make migrations?
python manage.py makemigrations
how do we run migrations?
python manage.py migrate
how do you create a super user in django
python manage.py createsuperuser
where do you register your models to work with admin?
admin.py
how do import your models (2 froms, admin.site)
from django.contrib import admin
from app.models import modelname
admin.site.register(modelname)
What query set methods are used most often to look up objects from the database?
all(), get(), filter() and exclude()
What is models.py?
Structure of the data and what fields they use.
What is views.py?
Holds class based or function based views, it handles request and return reponses.