|
| 1 | +Cookbook Example Django Project |
| 2 | +=============================== |
| 3 | + |
| 4 | +This example project demos integration between Graphene and Django. |
| 5 | +The project contains two apps, one named `ingredients` and another |
| 6 | +named `recepies`. |
| 7 | + |
| 8 | +Getting started |
| 9 | +--------------- |
| 10 | + |
| 11 | +First you'll need to get the source of the project. Do this by cloning the |
| 12 | +whole Graphene repository: |
| 13 | + |
| 14 | +```bash |
| 15 | +# Get the example project code |
| 16 | +git clone https://github.com/graphql-python/graphene.git |
| 17 | +cd graphene/examples/cookbook |
| 18 | +``` |
| 19 | + |
| 20 | +It is good idea (but not required) to create a virtual environment |
| 21 | +for this project. We'll do this using |
| 22 | +[virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/) |
| 23 | +to keep things simple, |
| 24 | +but you may also find something like |
| 25 | +[virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/) |
| 26 | +to be useful: |
| 27 | + |
| 28 | +```bash |
| 29 | +# Create a virtualenv in which we can install the dependencies |
| 30 | +virtualenv env |
| 31 | +source env/bin/activate |
| 32 | +``` |
| 33 | + |
| 34 | +Now we can install our dependencies: |
| 35 | + |
| 36 | +```bash |
| 37 | +pip install -r requirements.txt |
| 38 | +``` |
| 39 | + |
| 40 | +Now setup our database: |
| 41 | + |
| 42 | +```bash |
| 43 | +# Setup the database |
| 44 | +./manage.py migrate |
| 45 | + |
| 46 | +# Load some example data |
| 47 | +./manage.py loaddata ingredients |
| 48 | + |
| 49 | +# Create an admin user (useful for logging into the admin UI |
| 50 | +# at http://127.0.0.1:8000/admin) |
| 51 | +./manage.py createsuperuser |
| 52 | +``` |
| 53 | + |
| 54 | +Now you should be ready to start the server: |
| 55 | + |
| 56 | +```bash |
| 57 | +./manage.py runserver |
| 58 | +``` |
| 59 | + |
| 60 | +Now head on over to |
| 61 | +[http://127.0.0.1:8000/graphiql](http://127.0.0.1:8000/graphiql) |
| 62 | +and run some queries! |
| 63 | +(See the [Django quickstart guide](http://graphene-python.org/docs/quickstart-django/) |
| 64 | +for some example queries) |
0 commit comments