85👍
You can still do this :
cd app
django-admin startapp subapp1
This will work (create the application basic structure), however app
and subapp1
will still be considered as two unrelated applications in the sense that you have to add both of them to INSTALLED_APPS
in your settings.
Does this answer your question ? Otherwise you should tell more about what you are trying to do.
44👍
According to Django documentation,
If the optional destination is provided, Django will use that existing directory rather than creating a new one. You can use ‘.’ to denote the current working directory.
For example:
django-admin startapp myapp /Users/jezdez/Code/myapp
So, you can do it by this method:
- Create
sub_app1
directory inapp
directory python manage.py startapp sub_app1 app/sub_app1
- [Django]-Can I make an admin field not required in Django without creating a form?
- [Django]-How to escape {{ or }} in django template?
- [Django]-Do I need Nginx with Gunicorn if I am not serving any static content?
16👍
Its Simple
Step 1 – Create Project
django-admin startproject app
cd app
Step 2 – Create api folder
mkdir api
cd api
touch __init__.py
cd ..
Step 3 – Create nested apps
python manage.py startapp user ./api/user
python manage.py startapp post ./api/post
python manage.py startapp comment ./api/comment
Step 4 – Register nested apps
INSTALLED_APPS = [
...
'api.user',
'api.post',
'api.comment',
]
Step 5 – Change name of Apps
Update the name in apps.py files in all three apps
class UserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api.user'
class PostConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api.post'
class CommentConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api.comment'
and We are done!
Note : Step 2 is important
- [Django]-Getting a count of objects in a queryset in Django
- [Django]-Django query get last n records
- [Django]-Python + Django page redirect
14👍
Django doesn’t support “subapplications” per se. If you want code to be collected in packages within an app then just create them yourself. Otherwise you’re just asking for pain.
- [Django]-Django: Get an object form the DB, or 'None' if nothing matches
- [Django]-How to add multiple arguments to my custom template filter in a django template?
- [Django]-Django template includes slow?
- [Django]-CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
- [Django]-Django – what is the difference between render(), render_to_response() and direct_to_template()?
- [Django]-Error: No module named staticfiles
3👍
django-admin.py startapp myapp /Users/jezdez/Code/myapp
Reference: Django Admin documentation
- [Django]-How to concatenate strings in django templates?
- [Django]-Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet."
- [Django]-How to use MySQLdb with Python and Django in OSX 10.6?
2👍
In order to create a nested app in the Django project, you have to follow the following steps:
- Create a subdirectory in the parent directory where you want to add a sub-app.
mkdir finances/expences
N.B: Here finances
is the existing parent app and expenses
will be the next nested sub-app.
- If the subdirectory is created successfully then run the following command in the terminal.
python manage.py startapp expenses finances/expenses
Please check the expenses
subdirectory is now looks like a Django app and will behave like that.
Don’t forget to register this app in the settings file and change the name from the config file of the app expenses
, like –
class ExpensesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'finances.expenses'
Here, the name was only ‘expenses’ but it has been changed to ‘finances.expenses’ otherwise no migrations will be applied.
- [Django]-Filtering dropdown values in django admin
- [Django]-Class has no objects member
- [Django]-Token Authentication for RESTful API: should the token be periodically changed?
- [Django]-Django can' t load Module 'debug_toolbar': No module named 'debug_toolbar'
- [Django]-How do you log server errors on django sites
- [Django]-Django MEDIA_URL and MEDIA_ROOT
0👍
there is really no any differ if you use django-admin or manage.py in this case – both will create
https://docs.djangoproject.com/en/4.0/ref/django-admin/#django-admin-and-manage-py
In addition, manage.py is automatically created in each Django project. It does the same thing as django-admin but also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file.
- [Django]-How to read the database table name of a Model instance?
- [Django]-How to test custom django-admin commands
- [Django]-Django migrations RunPython not able to call model methods