Python Archives - Professional Application Development https://proappdev.com/category/python/ Get your apps developed professionally Sat, 06 Apr 2019 11:28:32 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.8 Django common commands cheat sheet https://proappdev.com/python/django-common-commands-cheat-sheet/ https://proappdev.com/python/django-common-commands-cheat-sheet/#respond Sat, 06 Apr 2019 11:26:45 +0000 https://proappdev.com/?p=1013 Here is the list of commands commonly used in django projects. All following commands are to be run from inside main app folder that we created with the first command. Below is a sample code that tell us how we can benefit from interactive shell. Using that we easily created two database entries using Track…

The post Django common commands cheat sheet appeared first on Professional Application Development.

]]>
Here is the list of commands commonly used in django projects.

django-admin startproject app #(Create main project)

All following commands are to be run from inside main app folder that we created with the first command.

python manage.py runserver #Run local server
python manage.py migrate #Run all database migrations
python manage.py makemigration #Create any new migration created file
python manage.py startapp <app_name> #Create new application within the main app folder
#application created using this command won't be automatically enabled, 
#but we need to go in app/app/settings.py and need to add our new application name at the end of INSTALLED_APPS list.
python manage.py shell #To open interactive Django shell like Tinker for Laravel

Below is a sample code that tell us how we can benefit from interactive shell. Using that we easily created two database entries using Track model of an application’s model.

(react-tracks) python manage.py shell
Python 3.7.2 (default, Nov 10 2011, 15:00:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from tracks.models import Track
>>> Track.objects.create(title="Track 1", desc="Track 1 description...", url="https://track1.com")
<Track: Track object (1)>
>>> Track.objects.create(title="Track 2", desc="Track 2 description...", url="https://track2.com")
<Track: Track object (2)>
>>> exit()

The post Django common commands cheat sheet appeared first on Professional Application Development.

]]>
https://proappdev.com/python/django-common-commands-cheat-sheet/feed/ 0