Working With Django Projects, The Basics: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 1: | Line 1: | ||
[[category:Django]] [[category:Python]] [[category:Web Development]] | [[category:Django]] [[category:Python]] [[category:Web Development]] | ||
== Creating a new project == | == Creating a new project<ref>[https://docs.djangoproject.com/en/1.7/intro/tutorial01/ Writing your first Django app, part 1] (Django project)</ref> == | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 8: | Line 8: | ||
== Define a database connection == | == Define a database connection == | ||
Enter database properties in `myproject/settings.py`, then from the project root: | Enter database properties in `myproject/settings.py`, then from the project root:<ref>[https://docs.djangoproject.com/en/1.7/intro/tutorial01/ Writing your first Django app, part 1] (Django project)</ref> | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 37: | Line 37: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The `makemigrations` and `migrate` commands are run anytime there is a change to the models.<ref>[https://docs.djangoproject.com/en/1.7/intro/tutorial01/ Writing your first Django app, part 1] (Django project)</ref> | |||
== Command-line API<ref>[https://docs.djangoproject.com/en/1.7/intro/tutorial01/ Writing your first Django app, part 1] (Django project)</ref> == | |||
<syntaxhighlight lang="bash"> | |||
$ python manage.py shell | |||
</syntaxhighlight> | |||
== Create an admin user == | |||
<syntaxhighlight lang="bash"> | |||
$ python manage.py createsuperuser | |||
</syntaxhighlight> | |||
And then enter in credentials using the prompts.<ref>[https://docs.djangoproject.com/en/1.7/intro/tutorial02/ Writing your first Django app, part 2] (Django project)</ref> | |||
== Notes == | |||
<references /> | |||
Latest revision as of 16:02, 22 March 2015
Creating a new project[1]
$ django-admin.py startproject mysite
Define a database connection
Enter database properties in myproject/settings.py, then from the project root:[2]
$ python manage.py migrate
Run the server
$ python manage.py runserver
The server address will be reported in the output of that command, typically http://127.0.0.1:8000/
Add an app
$ python manage.py startapp myapp
- Define some models in
myapp/models.py. - Add the app name to
INSTALLED_APPSinmysiet/settings.py. - Then:
$ python manage.py makemigrations myapp $ python manage.py migrate
The makemigrations and migrate commands are run anytime there is a change to the models.[3]
Command-line API[4]
$ python manage.py shell
Create an admin user
$ python manage.py createsuperuser
And then enter in credentials using the prompts.[5]
Notes
- ↑ Writing your first Django app, part 1 (Django project)
- ↑ Writing your first Django app, part 1 (Django project)
- ↑ Writing your first Django app, part 1 (Django project)
- ↑ Writing your first Django app, part 1 (Django project)
- ↑ Writing your first Django app, part 2 (Django project)