diff options
| author | Tom Christie | 2013-06-05 13:33:19 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-06-05 13:33:19 +0100 |
| commit | de00ec95c3007dd90b5b01f7486b430699ea63c1 (patch) | |
| tree | d2ce8037d446fd9133b3d6a77ebcc49350d7ebc3 /docs/tutorial/quickstart.md | |
| parent | 9428d6ddb5ebc2d5d9c8557a52be09f0def69cca (diff) | |
| parent | 2ca243a1144bb2a5461767a21ed14dec1d2b8dc2 (diff) | |
| download | django-rest-framework-de00ec95c3007dd90b5b01f7486b430699ea63c1.tar.bz2 | |
Merge master
Diffstat (limited to 'docs/tutorial/quickstart.md')
| -rw-r--r-- | docs/tutorial/quickstart.md | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md index 52fe3acf..f15e75c0 100644 --- a/docs/tutorial/quickstart.md +++ b/docs/tutorial/quickstart.md @@ -2,7 +2,43 @@ We're going to create a simple API to allow admin users to view and edit the users and groups in the system. -Create a new Django project, and start a new app called `quickstart`. Once you've set up a database and got everything synced and ready to go open up the app's directory and we'll get coding... +## Project setup + +Create a new Django project named `tutorial`, then start a new app called `quickstart`. + + # Set up a new project + django-admin.py startproject tutorial + cd tutorial + + # Create a virtualenv to isolate our package dependencies locally + virtualenv env + source env/bin/activate + + # Install Django and Django REST framework into the virtualenv + pip install django + pip install djangorestframework + + # Create a new app + python manage.py startapp quickstart + +Next you'll need to get a database set up and synced. If you just want to use SQLite for now, then you'll want to edit your `tutorial/settings.py` module to include something like this: + + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'database.sql', + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '' + } + } + +The run `syncdb` like so: + + python manage.py syncdb + +Once you've set up a database and got everything synced and ready to go, open up the app's directory and we'll get coding... ## Serializers @@ -55,7 +91,7 @@ We can easily break these down into individual views if we need to, but using vi ## URLs -Okay, now let's wire up the API URLs. On to `quickstart/urls.py`... +Okay, now let's wire up the API URLs. On to `tutorial/urls.py`... from django.conf.urls import patterns, url, include from rest_framework import routers @@ -80,7 +116,7 @@ Finally, we're including default login and logout views for use with the browsab ## Settings -We'd also like to set a few global settings. We'd like to turn on pagination, and we want our API to only be accessible to admin users. +We'd also like to set a few global settings. We'd like to turn on pagination, and we want our API to only be accessible to admin users. The settings module will be in `tutorial/settings.py` INSTALLED_APPS = ( ... @@ -98,6 +134,10 @@ Okay, we're done. ## Testing our API +We're now ready to test the API we've built. Let's fire up the server from the command line. + + python ./manage.py runserver + We can now access our API, both from the command-line, using tools like `curl`... bash: curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/ |
