Django 2 Flashcards
Which command lets you start a Django project?
django-admin startproject mysite
where mysite is the name of the directory.
What arborescence does the startproject command create?
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is the outer mysite/?
The outer mysite/ root directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is manage.py?
manage.py is a command-line utility that lets you interact with this Django project in various ways.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is the inner mysite/?
The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is mysite/__init__.py?
mysite/__init__.py is an empty file that tells Python that this directory should be considered a Python package.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is mysite/settings.py?
mysite/settings.py is the settings/configuration for this Django project.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is mysite/urls.py?
mysite/urls.py is the URL declarations for this Django project; a “table of contents” of your Django-powered site.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
What is mysite/wsgi.py?
mysite/wsgi.py is an entry-point for WSGI-compatible web servers to serve your project.
Which command lets you start the development server?
python manage.py runserver
How do you specify a custom port when starting the development server?
python manage.py runserver 8080
How does automatic reloading work with runserver?
The development server automatically reloads Python code for each request as needed. You don’t need to restart the server for code changes to take effect. However, some actions like adding files don’t trigger a restart, so you’ll have to restart the server in these cases.
Which command lets you start an app with Django?
python manage.py startapp appname
Which command lets you create a virtual environement called myenv?
virtualenv myenv
Which command lets you activate a virtual environment?
source my_env/bin/activate
Which command lets you deactivate an environment?
source myenv/bin/deactivate
Where do packages get installed in your virtual environment?
myenv/lib/python3.7/site-packages
Which django function lets you check your Django version?
django.get_version()
How do you create create the tables in the database required by the applications listed in INSTALLED_APPS?
python mysite/manage.py migrate
What happens when you apply migrations?
By applying migrations, the tables for the initial applications are created in the database.
Is Django’s server suitable for production use?
No, runserver is suitable for development. In order to deploy Django in a production environment, you should run it as a WSGI application using a real web server, such as Apache, Gunicorn, or uWSGI.
In settings.py, what is the DEBUG setting?
DEBUG is a boolean that turns the debug mode of the project on and off. If it is set to True, Django will display detailed error pages when an uncaught exception is thrown by your application. When you move to a production environment, remember that you have to set it to False. Never deploy a site into production with DEBUG turned on because you will expose sensitive project-related data.
In settings.py, what is ALLOWED_HOSTS?
ALLOWED_HOSTS is not applied while debug mode is on, or when the tests are run. Once you move your site to production and set DEBUG to False, you will have to add your domain/host to this setting in order to allow it to serve your Django site.
In settings.py, what is INSTALLED_APPS?
INSTALLED_APPS is a setting you will have to edit for all projects. This setting tells Django which applications are active for this site.
What is the default installed app django.contrib.admin?
django.contrib.admin is an administration site.
What is the default installed app django.contrib.auth?
django.contrib.auth is an authentication framework.
What is the default installed app django.contrib.contenttypes?
django.contrib.contenttypes is a framework for handling content types.