Skip to content

Instantly share code, notes, and snippets.

@iruslani
Created July 5, 2012 22:02
Show Gist options
  • Save iruslani/3056761 to your computer and use it in GitHub Desktop.
Save iruslani/3056761 to your computer and use it in GitHub Desktop.
Django Command Notes
###Python Command Notes:###
#How to start the server:
>python manage.py runserver
# then you can view the page here: (http://127.0.0.1:8000/)
#How to start the python interpreter:
#(You can then run python commands)
>python
#How to create a new site
#run this command in the same directory you want the site created.
>django-admin.py startproject mysite
#if you dont have the path setup go to the directory and type this on dos:
c:\Python27\Scripts\django-admin.py startproject project_name
#To create an app, type this in the site directory:
>python manage.py startapp books
#How to start the interpreter with django template settings
>python manage.py shell
#How to find out the django version and find out if django is running on your server:
>import django
>django.VERSION
#To quit the python interpreter and go back to dos#
>quit()
###Django database Notes###
#To Validate the models:
>python manage.py validate
#To run the SQL command for the app books (This does not create the database):
>python manage.py sqlall books
#If the last commands looks good, here is the command to sync the db and create it:
>python manage.py syncdb
###SQLite3 Notes###
#Just create a database file in your windows directory, you dont need to go through sqlite3 or the console commands to do that.
#When you install SQLite, make sure its in your windows path so you can execute the SQLite in the command prompt.
#To open a db in sqlite3, go to the directory of your db and type in:
>sqlite3 [name of your db]
#SQLite3 comes with Python, you dont need to install from my experience.
#Download the sqlite-shell program to run the console here:
http://www.sqlite.org/download.html
#You need to get into the console to create a database table and ultimately save it to a file.
#When you run the console exe program, you get a dos prompt with the "sqlite>" prompt,
#this means you can initiate sqlite commands.
#type this for a list of commands inside the sqlite console:
.help
#This is how it could work for sqlite, which does not allow to modify a column directly (http://www.sqlite.org/lang_altertable.html):
ALTER TABLE books_book RENAME TO tmp_books_book;
CREATE TABLE "books_book" ( "id" integer NOT NULL PRIMARY KEY, "title" varchar(100) NOT NULL, "publisher_id" integer NOT NULL REFERENCES "books_publisher" ("id"), "publication_date" date NULL );
INSERT INTO books_book(id, title, publisher_id, publication_date) SELECT id, title, publisher_id, publication_date FROM tmp_books_book;
DROP TABLE tmp_books_book;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment