I just installed django and I'm doing the tutorial on their website.
I'm following their instructions on command line and they're working, but I'm wondering why?
For instance, you can access the command 'manage.py startapp xyz' and it would create a package, but when I look into manage.py, it only contains the following code (added by django, I didn't touch manage.py)
#!/usr/bin/env python import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoProject12.settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
I don't see any method for startapp in manage.py or anywhere else. I'm not sure if this is django specific or if there is some fundamental gap in my python knowledge. Thank you.
manage.py : A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py. The inner mysite/ directory is the actual Python package for your project.
Django-admin.py: It is a Django's command line utility for administrative tasks. Manage.py: It is an automatically created file in each Django project.
You can run manage.py from anywhere. No need to activate a virtualenv or be in the right directory. Simply run /path/to/virtualenv/bin/manage.py ... and it just works. If your virtualenv is activated, the path will already be set and manage.py will just work without the path.
You need to look in the django.core.management
package; the execute_from_command_line()
function accepts the sys.argv
command line parameters and takes it from there.
When you enter manage.py startapp xyz
on the command line, sys.argv
is set to ['manage.py', 'startapp', 'xyz']
.
These are handed off to a ManagementUtility
instance, which has a .execute()
method to do the actual parsing.
The whole django.core.management
package is modular; the .commands
sub package contains the various standard commands for the manage.py
tool. django.core.management.commands.startapp
handles the startapp
subcommand, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With