Django create new app
To create a new app in Django, you can use the following command:
python manage.py startapp app_name
Replace app_name
with the name of your app. For example, if you want to create an app called myapp
, you would run:
python manage.py startapp myapp
This will create a new directory called myapp
in your project directory, with the following structure:
myapp/
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
templates/
static/
__init__.py
settings.py
urls.py
Here's a brief description of each file:
__init__.py
: An empty file that tells Python that this directory should be treated as a Python package.admin.py
: A file where you can define custom admin interfaces for your app's models.apps.py
: A file where you can define metadata about your app, such as its name and dependencies.models.py
: A file where you can define your app's models using Django's ORM.tests.py
: A file where you can write unit tests for your app.views.py
: A file where you can define views for your app, which handle HTTP requests and return HTTP responses.templates/
: A directory where you can store HTML templates for your app.static/
: A directory where you can store static files, such as CSS and JavaScript files.settings.py
: A file where you can define settings for your app, such as the app's name and URL patterns.urls.py
: A file where you can define URL patterns for your app.
Once you've created your app, you'll need to add it to your project's INSTALLED_APPS
setting in settings.py
. You can do this by adding the following line:
INSTALLED_APPS = [
#...
'myapp.apps.MyappConfig',
#...
]
Replace myapp
with the name of your app, and MyappConfig
with the name of the AppsConfig
class in your app's apps.py
file.
That's it! You've now created a new app in your Django project.