Overview
This week we setup our Django development environment and begin learning Django.
Wednesday, March 15th
Classwork
I'm out sick again today. Since we are starting something new (Django development), and since I really need to be there to be sure you have your development environments setup correctly before we move forward, please use today to catch up with the work I know you have in other classes, and we will move forward with Django when I see you in class on Friday.
Monday, March 11th
Classwork
I'm out sick (I've been sick all weekend). Please work together in your groups and see if you can help each other through the basic Django setup in my absence.
Today we will setup our Django development environments on our school
laptops, by cloning
gctaa_dj4e_samples
and following the setup instructions in the README.md
file.
The next steps are presented by Dr. Chuck in the Installing Django on PythonAnywhere video here. Since we won't be using PythonAnywhere, we'll do this together in class where I can help guide you through the differences and where we can help each other out.
After you finish the steps in the README.md
file, you will:
-
Create a new directory in the same parent directory where you cloned
gctaa_dj4e_samples
nameddjango_projects
. -
Activate the virtual environment you created in
gctaa_dj4e_samples
with:% source ~/gctaa_dj4e_samples/.env/bin/activate
then change to the newdjango_projects
directory:(.env) cd ~/django_projects
and run:(.env) django-admin startproject mysite
-
Edit the
~/django_projects/mysite/mysite/settings.py
file (using vim, of course ;-) and change the line:ALLOWED_HOSTS = []
toALLOWED_HOSTS = ['*']
-
Now test your setup by first changing to your outer
mysite
directory:(.env) cd ~/django_projects/mysite
(NOTE: Running thels
command here you should see:manage.py mysite
) and then starting the django webserver with:(.env) python manage.py runserver 0.0.0.0:8080
-
Point your web browser at
localhost:8080
and you should see:You will also see the following error message in the console:
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.
We can fix this by doing what the message tells us to do. You can use
Control-C
on your keyboard to stop the development server. -
We now create our first Django app with:
(.env) python manage.py startapp polls
Homework
Complete the rest of the Writing your first Django app, part 1 tutorial. Be sure to activate your virtual environment with:
% source ~/gctaa_dj4e_samples/.env/bin/activate
whenever working in your django_projects
directory. Activating
and deactivating your virtual environment, and down the road switching between
virtual environments for different projects, is something you will need to
become comfortable with.
Come to class on Wednesday ready to show me a screen like this:
running on your school laptop.