Szworny Dziąch Szworny Dziąch - 5 months ago 24
Python Question

Adding new django rest framework app to settings

I'm going through this tutorial: http://www.django-rest-framework.org/tutorial/1-serialization/ and there's one thing I don't understand a bit. They are doing

python manage.py startapp snippets
and adding
'snippets.apps.SnippetsConfig'
to
INSTALLED_APPS
. Why this and not
'snippets'
? When I start a new app no
apps
package gets created and neither
WhateverConfig
.

Answer

If you are using below djagno1.9 just add snippets. In older django versions startapp management command will not create apps.py. you have to create new apps.py.

For > Django 1.9 apps.py creates with startapp command

(env) simple: python manage.py startapp snippets
(env) simple: find snippets 
snippets
snippets/models.py
snippets/tests.py
snippets/views.py
snippets/admin.py
snippets/__init__.py
snippets/apps.py   # your apps.py
snippets/migrations
snippets/migrations/__init__.py

(env) simple: cat snippets/apps.py 
from __future__ import unicode_literals

from django.apps import AppConfig


class SnippetsConfig(AppConfig):
    name = 'snippets'

The Rest-Framework Documentation Updated to Django 1.9. Commit updated tutorial for django 1.9 on GitHub

Read more about apps.py in django 1.9