Course Home | Syllabus | Assignments | Schedule | Examples | Grades | Submissions | [print]

Examples and Hints

Examples will be generated from the code generated in class. The examples can be accessed at https://github.com/danemco/CS4990.

Google Group

The Google group and mailing list for the class is at https://groups.google.com/forum/#!forum/dsu-cs4990-fall-2015. You need to be invited to join the group.

Django Reference

Virtual Evnironments and Installing Django

Let’s assume your home directory is /home/j/jdoe/, and you want to put all of your Django assigments under a subdirectory named django:

mkdir django

To set up your virtual environment, run this command next:

virtualenv django

You’re now ready to activate your virtual environment!

cd django source bin/activate

Once you’re finished, remember to deactivate to return your shell back to normal:

deactivate

When you return to your django project at another time, don’t forget to actiave the virtual environment again:

cd django source bin/activate

Once you’ve activated your virtual environment, to install Django, run this command:

pip install Django

Generating A Requirements File

When submitting projects that use other apps that you’ve installed into your virtual environment, the easiest way to communicate those apps is through requirements files. These requirements files can be included with the assignments that you turn in.

This is the command you run to generate a requirements file

source bin/activate # if you haven't already activated your virtual environment

pip freeze > requirements.txt

For the curious, this is how you install the packages from the list of requirements:

pip install -r requirements.txt

You can then have a similar copy of the environment that someone set up for you

SSH Tunnelling for Run Server

SSH Tunnelling can make your life a lot easier. This is how I do it to test my runserver:

ssh -l dpurcell ssh.cs.dixie.edu -L 8000:localhost:8000

…and from there, ssh into the maching I’m developing on again:

ssh -l dpurcell nitrogen.cs.dixie.edu -L 8000:localhost:8000

I know it’s a double tunnel but that’s the only way I’ve figured out how to get it to work for me from home.

I can then point my browser to http://localhost:8000 and it picks up the port 8000 on the development server.

Using Fixtures to Populate The Database

To save off a copy of your database data, run this for each app, where appname is the name of your app (e.g. polls):

python manage.py dumpdata appname > appname-data.json

If you want to read in the data, use the following command:

python manage.py loaddata appname-data.json

Troubleshooting

Last Updated 08/24/2015