Difference between revisions of "Django"

From ArchWiki
Jump to: navigation, search
(Added eric4 IDE setup... Hidden config settings.)
(Usage: Wiki article now references `django-admin3.py` instead of `django-admin.py`.)
(18 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[Category:Development (English)]]
+
[[Category:Development]]
[http://www.djangoproject.com Django] is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
+
[[fr:Django]]
=Installation=
+
''"[http://www.djangoproject.com Django] is a high-level [[Python]] Web framework that encourages rapid development and clean, pragmatic design."''
Django can be installed through pacman by installing the 'django' package.
+
 
<pre>
+
{{Note|Django 1.5 is the first Django release with support for Python 3 (specifically, Python 3.2 and newer). Python 3 support is still considered experimental, but there is a [https://docs.djangoproject.com/en/1.5/topics/python3/ porting guide] if you would like to try it out.}}
# pacman -S django
+
==Installation==
</pre>
+
 
There is also an svn PKGBUILD available in the AUR, 'django-svn'. Using yaourt it can be installed as follows.
+
[[pacman|Install]] {{Pkg|python-django}} or {{Pkg|python2-django}}, for Python 3 or Python 2 support respectively, from the [[Official Repositories]].
<pre>
+
 
# yaourt -S django-svn
+
==Usage==
</pre>
+
Django is not used like other python libraries for the most part, but it can be. After installation, you should be able to simply import django in any python script.
Of course, you can always download it directly from [http://www.djangoproject.com/download/ The Official Website]
+
 
 +
>>> import django
 +
 
 +
In order to start a project, use django-admin3.py.
 +
 
 +
$ django-admin3.py startproject myproject
  
=Usage=
 
Django is not used like other python libraries for the most part, but it can. After installation, you should be able to simply import django in any python script.
 
<pre>
 
>>> import django
 
</pre>
 
In order to start a project, use django-admin.py.
 
<pre>
 
$ django-admin.py startproject myproject
 
</pre>
 
 
This will create the directory ''myproject'' under the current directory. It will also create the ''manage.py'' script, which has more useful functions for managing and testing your project. For instance, django has a small test server built into ''manage.py''.
 
This will create the directory ''myproject'' under the current directory. It will also create the ''manage.py'' script, which has more useful functions for managing and testing your project. For instance, django has a small test server built into ''manage.py''.
<pre>
+
{{bc|
 
$ python2 manage.py runserver
 
$ python2 manage.py runserver
 
Validating models...
 
Validating models...
Line 30: Line 26:
 
Development server is running at http://127.0.0.1:8000/
 
Development server is running at http://127.0.0.1:8000/
 
Quit the server with CONTROL-C.
 
Quit the server with CONTROL-C.
</pre>
+
}}
 
It can be changed to run at, say, port 8080 like so.
 
It can be changed to run at, say, port 8080 like so.
<pre>
+
{{bc|
 
$ python2 manage.py runserver 8080
 
$ python2 manage.py runserver 8080
 
Validating models...
 
Validating models...
Line 40: Line 36:
 
Development server is running at http://127.0.0.1:8080/
 
Development server is running at http://127.0.0.1:8080/
 
Quit the server with CONTROL-C.
 
Quit the server with CONTROL-C.
</pre>
+
}}
 
For more help, please see the [http://www.djangobook.com Django Book] or [http://docs.djangoproject.com/en/dev/ Official Django Documentation]
 
For more help, please see the [http://www.djangobook.com Django Book] or [http://docs.djangoproject.com/en/dev/ Official Django Documentation]
  
=eric4-IDE Tips & Tricks=
+
==eric-IDE Tips & Tricks==
Eric4 is a good IDE for Django. It has Highlighting, Autocompletion, CVS & Subversion, Debugger, and Breakpoints.
+
Eric is a good IDE for Django. It has Highlighting, Autocompletion, CVS & Subversion, Debugger, and Breakpoints.
  
First install eric4 and eric-plugins
+
{{Pkg|eric}} (Python 3) and {{Pkg|eric4}} (Python 2) can be [[pacman|installed]] from the [[official repositories]].
<pre>
+
pacman -S eric eric-plugins
+
</pre>
+
  
 
To start a new Django Project.
 
To start a new Django Project.
First click on the Project/new
+
 
 +
First click on the "Project/new."
 
Then under "Project Type" select Django.
 
Then under "Project Type" select Django.
Then after the django project has been created, Right-click on the Project-Fiewer to the Left and select "Configure", and set "Projecttype" to Django in the configuration window.
+
After your new django project has been created, Right-click on the "Project Viewer", to the Left, and select "Configure", and in the configuration window set "Project type" to Django.
  
After that, in the eric4 "Settings/Preferences" select Django from the left, and change the "Console Command" to ,If KDE,
+
After that, in eric4's "Settings/Preferences" select Django, from the left, and add this change to the "Console Command."
<pre>
+
 
konsole --workdir `pwd` -e
+
If KDE,
konsole --workdir `pwd` --noclose -e
+
 
</pre>
+
konsole --workdir `pwd` -e
 +
konsole --workdir `pwd` --noclose -e
  
 
This will solve the problem...
 
This will solve the problem...
<pre>
+
 
/usr/bin/python2: can't open file 'manage.py': [Errno 2] No such file or directory
+
/usr/bin/python2: can't open file 'manage.py': [Errno 2] No such file or directory
</pre>
+
  
 
Note the "Django" menu next to "Project" and "Extras". There you will find Django tools to runserver and sync database.
 
Note the "Django" menu next to "Project" and "Extras". There you will find Django tools to runserver and sync database.
  
 
Now, just play around with it a little. All your Python code will be Added to the first tab of the "Project-Viewer" and your html templates will be opened in the second tab.
 
Now, just play around with it a little. All your Python code will be Added to the first tab of the "Project-Viewer" and your html templates will be opened in the second tab.

Revision as of 15:05, 3 April 2013

"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design."

Note: Django 1.5 is the first Django release with support for Python 3 (specifically, Python 3.2 and newer). Python 3 support is still considered experimental, but there is a porting guide if you would like to try it out.

Installation

Install python-django or python2-django, for Python 3 or Python 2 support respectively, from the Official Repositories.

Usage

Django is not used like other python libraries for the most part, but it can be. After installation, you should be able to simply import django in any python script.

>>> import django

In order to start a project, use django-admin3.py.

$ django-admin3.py startproject myproject

This will create the directory myproject under the current directory. It will also create the manage.py script, which has more useful functions for managing and testing your project. For instance, django has a small test server built into manage.py.

$ python2 manage.py runserver
Validating models...
0 errors found

Django version 1.1, using settings 'modsite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

It can be changed to run at, say, port 8080 like so.

$ python2 manage.py runserver 8080
Validating models...
0 errors found

Django version 1.1, using settings 'modsite.settings'
Development server is running at http://127.0.0.1:8080/
Quit the server with CONTROL-C.

For more help, please see the Django Book or Official Django Documentation

eric-IDE Tips & Tricks

Eric is a good IDE for Django. It has Highlighting, Autocompletion, CVS & Subversion, Debugger, and Breakpoints.

eric (Python 3) and eric4 (Python 2) can be installed from the official repositories.

To start a new Django Project.

First click on the "Project/new." Then under "Project Type" select Django. After your new django project has been created, Right-click on the "Project Viewer", to the Left, and select "Configure", and in the configuration window set "Project type" to Django.

After that, in eric4's "Settings/Preferences" select Django, from the left, and add this change to the "Console Command."

If KDE,

konsole --workdir `pwd` -e
konsole --workdir `pwd` --noclose -e

This will solve the problem...

/usr/bin/python2: can't open file 'manage.py': [Errno 2] No such file or directory

Note the "Django" menu next to "Project" and "Extras". There you will find Django tools to runserver and sync database.

Now, just play around with it a little. All your Python code will be Added to the first tab of the "Project-Viewer" and your html templates will be opened in the second tab.