The provided modules are sometimes needed and sometimes not.
Sometimes, apps are created for SRP, which means they are created to isolate a functionality in an app. For instance, a project might have an ajax app for providing JSON endpoints to bring dynamism to a web page or a rest app to isolate REST endpoints.
Sometimes, apps are created as an extension. For instance, if a project has a different text formatting specification (like BBCode), it is better to isolate it into an app.
Sometimes, apps are created to isolate a part of whole project. Let's say we have a web app with a homepage, a forum, a QA platform and a messaging platform. We would create separate apps for each.
So, adding models, views, tests and not including urls module is not always desirable. We can, however, provide a command that can create an app interactively, asking what part exactly a developer needs.
createapp will be a command in core app. It is an alternative to startapp command but different in behavior.
Interactivity
Upon python3 manage.py createapp, an interactive session will start. It is represented in order in the table below.
Note
In the table below, a module is a single py file while package is a directory with __init__.py in it.
Condition
Order
Question
Answer Type
Default Answer
Description
-
1
Would you like to have models in your app?
y/n/Y/N
y
1. Creates models module. 2. Adds # noqa comment at the end of models import. 3. Adds a # TODO remove noqa comment above import. 4. Adds explanation as to factories and drawio files.
If y to 1
2
Would you like to have factories in your app?
y/n/Y/N
y
1. Creates factories module. 2. Adds appname.factories to conftest.py at root. 3. Adds explanation as to how to write factories.
If y to 1
3
Would you like to create arch.drawio file?
y/n/Y/N
n
Creates arch.drawio file.
-
4
Would you like to have views in your app?
y/n/Y/N
y
Creates views package.
If y to 4
5
Would you like to have urls in your app?
y/n/Y/N
y
1. Creates urls module.\n 2. Adds app_name variable to urls module so we can have namepsaces on urls. 3. Adds urlpatterns list. 4. Imports path and adds # noqa comment at the end. 5. Adds appname.urls to projects.url module.
If y to 5
6
What should be the root URL for your app?
text
empty
If left empty, attaches url to the root url.
-
7
Would you like admin integration for your app?
y/n/Y/N
n
1. Creates admin module. 2. Imports admin and adds # noqa to the end.
If y to 4
8
Would you like Laravel Mix support?
y/n/Y/N
n
Sets up Laravel Mix for the app.
Gitignore
A .gitignore should be present at the root of each app so that it won't include unwanted files on commit.
See #50.
The provided modules are sometimes needed and sometimes not.
ajax
app for providing JSON endpoints to bring dynamism to a web page or arest
app to isolate REST endpoints.So, adding
models
,views
,tests
and not includingurls
module is not always desirable. We can, however, provide a command that can create an app interactively, asking what part exactly a developer needs.createapp
will be a command incore
app. It is an alternative tostartapp
command but different in behavior.Interactivity
Upon
python3 manage.py createapp
, an interactive session will start. It is represented in order in the table below.y
/n
/Y
/N
y
models
module.2. Adds
# noqa
comment at the end ofmodels
import.3. Adds a
# TODO remove noqa
comment above import.4. Adds explanation as to
factories
anddrawio
files.y
to 1y
/n
/Y
/N
y
factories
module.2. Adds
appname.factories
toconftest.py
at root.3. Adds explanation as to how to write factories.
y
to 1arch.drawio
file?y
/n
/Y
/N
n
arch.drawio
file.y
/n
/Y
/N
y
views
package.y
to 4y
/n
/Y
/N
y
urls
module.\n2. Adds
app_name
variable tourls
module so we can have namepsaces on urls.3. Adds
urlpatterns
list.4. Imports
path
and adds# noqa
comment at the end.5. Adds
appname.urls
toprojects.url
module.y
to 5y
/n
/Y
/N
n
admin
module.2. Imports
admin
and adds# noqa
to the end.y
to 4y
/n
/Y
/N
n
Gitignore
A
.gitignore
should be present at the root of each app so that it won't include unwanted files on commit.