Skip to content

Instantly share code, notes, and snippets.

@titipata
Last active October 2, 2018 07:48
Show Gist options
  • Save titipata/0c740442d3b7be89180a to your computer and use it in GitHub Desktop.
Save titipata/0c740442d3b7be89180a to your computer and use it in GitHub Desktop.
django notes for creating webpage

Django Notes

  • This is a note after following the tutorial on django tutorial website
  • MVC Model View Control framework provide a way to structure your website
  • DRY = don't repeat yourself
  • Visit Django website and Django tutorial (with youtube video)

Download django and install by sudo python setup.py install To start project, simply type

django-admin.py startproject "project-name"

Project structure for django is as follow:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Then we can run many command from manage.py as follows:

python manage.py migrate		(deal with database)
python manage.py shell 		(to run the shell)
python manage.py run server [port number e.g 8080]	(to run server)
python manage.py syncdb		(to sync with database)

We should run migrate for the database thing: python manage.py migrate. Then, to create first app, we'll use manage.py file again

python manage.py startapp "app-name" (to create application)

For the application, polls/models.py is the file that we will put some python class inherit models as we can see in the fime from django.db import models. Then each class will start with something like class Question(models.Model):

Here, after creating application, go to mysite/settings.py file then add app-name in to INSTALLED_APPS = (...)

Then run another command python manage.py makemigrations polls

###Django Session

  • Go to this link on how to create Django Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment