Django Development with IIS: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 23: Line 23:


== Accessing projects ==  
== Accessing projects ==  
=== Goals ===
* '''Local development''': Access the project using `<nowiki>http://localmachine:8080:/MyDjangoProject/</nowiki>`
* '''Public access''': Access the project using `<nowiki>http://staging.devdomain.com:8080:/MyDjangoProject/</nowiki>`
* N.B. The Apache server needs to be restarted for any changes to the code to take effect.
* N.B. It's very insecure to allow public access.
=== Workflow ===


For each Django Project:
For each Django Project:
Line 28: Line 37:
<tt>
<tt>
import os, sys<br />
import os, sys<br />
sys.path.append('<em>/path/to/your/django/projects/folder</em>')<br />
sys.path.append('<em>/path/to/your/project/folder</em>')<br />
sys.path.append('<em>/path/to/your/project/folder</em>')<br />
os.environ['DJANGO_SETTINGS_MODULE'] = '<em>projectName.settings</em>'<br />
os.environ['DJANGO_SETTINGS_MODULE'] = '<em>projectName.settings</em>'<br />
Line 36: Line 44:
application = django.core.handlers.wsgi.WSGIHandler()
application = django.core.handlers.wsgi.WSGIHandler()
</tt>
</tt>
* After saving the WSGI file, create an Apache configuration file named `''projectName''.conf` in `''installdir''/apps/django/conf` to load it.
<tt>
Alias /static "<em>installdir</em>/apps/django/lib/python-version/site-packages/django/contrib/admin/static"<br />
<Directory '<em>installdir</em>/apps/django/lib/python-version/site-packages/django/contrib/'><br />
Order allow,deny<br />
Allow from all<br />
</Directory><br />
WSGIScriptAlias /<em>URL_mount_point</em> "<em>installdir</em>/apps/django/scripts/<em>projectName</em>.wsgi"<br />
<Directory '<em>installdir</em>/apps/django/scripts'><br />
Order allow,deny<br />
Allow from all<br />
</Directory><br />
</tt>
* Edit the file 'httpd.conf' and add the following line:
<tt>
Include "<em>installdir</em>/apps/django/conf/<em>projectName</em>.conf"
</tt>
* Restart the Apache server.
''N.B. Paths on Windows should use Unix-style forward slashes:'' `c:/path/to/dir/`


Source: [http://wiki.bitnami.org/Infrastructure_Stacks/BitNami_Django_Stack#How_to_create_a_new_Django_project.3f BitNami Django Stack Wiki: How to Start a Django Project?]
Source: [http://wiki.bitnami.org/Infrastructure_Stacks/BitNami_Django_Stack#How_to_create_a_new_Django_project.3f BitNami Django Stack Wiki: How to Start a Django Project?]


[[Category:Django]] [[Category:Python]] [[Category:Web Development]]
=== Making requests to the project ===
 
==== Local network ====
 
Access the project with either the local IP or network name of the server: `<nowiki>http://machinename:8080/DjangoProjectName</nowiki>`
 
==== Public access ====
 
* Open port `8080` (or whatever port the Apache server is using) on the router.
* Access the project using the default URL within IIS: `<nowiki>http://www.devdomain.com:8080/DjangoProjectName</nowiki>`
* N.B. the Windows versions of all the necessary software are not secure. Public access to the Django project running on IIS should only be allowed on a temporary basis and only if there is a compelling reason.
 
== See also ==
 
* [[Running a Django Application on IIS]]
 
[[Category:Django]] [[Category:Python]] [[Category:MVC]] [[Category:Windows]] [[Category:Web Development]]

Latest revision as of 22:01, 25 September 2013

Overview[edit]

Information about setting up Django projects on IIS.

Prerequisites[edit]

BitNami Django Stack[edit]

The BitNami Django Stack is a bundle of installers for the whole environment necessary to run Django on a Windows server. It includes Python, MySQL, PostgreSQL, an Apache server, and Django.

The installation prompts for a port number to use for the Apache server. 8080 is commonly used.

The Apache server can then be reached with `http://localhost:8080. Or, after opening the port in Windows Firewall, the server can be reached on the LAN with http://[MACHINE_NAME]:8080 or http://[LOCAL_IP]:8080`.

Changing the Apache server port number[edit]

To change the port number of the Apache server after installation:

  • Edit the Listen value in the [DJANGO_INSTALL_ROOT]/apache2/conf/httpd.conf file.
  • Restart the server.
  • (Windows Start Menu > BitNami DjangoStack > Manager Tool > Apache Web Server > Restart)

Accessing projects[edit]

Goals[edit]

  • Local development: Access the project using `http://localmachine:8080:/MyDjangoProject/
  • Public access: Access the project using http://staging.devdomain.com:8080:/MyDjangoProject/`
  • N.B. The Apache server needs to be restarted for any changes to the code to take effect.
  • N.B. It's very insecure to allow public access.

Workflow[edit]

For each Django Project:

  • Create a WSGI application script file named projectName.wsgi in [DJANGO_INSTALL_DIR]/appls/django/conf.

import os, sys
sys.path.append('/path/to/your/project/folder')
os.environ['DJANGO_SETTINGS_MODULE'] = 'projectName.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

  • After saving the WSGI file, create an Apache configuration file named projectName.conf in installdir/apps/django/conf to load it.

Alias /static "installdir/apps/django/lib/python-version/site-packages/django/contrib/admin/static"

<Directory 'installdir/apps/django/lib/python-version/site-packages/django/contrib/'>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias /URL_mount_point "installdir/apps/django/scripts/projectName.wsgi"

<Directory 'installdir/apps/django/scripts'>
Order allow,deny
Allow from all
</Directory>

  • Edit the file 'httpd.conf' and add the following line:

Include "installdir/apps/django/conf/projectName.conf"

  • Restart the Apache server.

N.B. Paths on Windows should use Unix-style forward slashes: c:/path/to/dir/

Source: BitNami Django Stack Wiki: How to Start a Django Project?

Making requests to the project[edit]

Local network[edit]

Access the project with either the local IP or network name of the server: `http://machinename:8080/DjangoProjectName`

Public access[edit]

  • Open port 8080 (or whatever port the Apache server is using) on the router.
  • Access the project using the default URL within IIS: `http://www.devdomain.com:8080/DjangoProjectName`
  • N.B. the Windows versions of all the necessary software are not secure. Public access to the Django project running on IIS should only be allowed on a temporary basis and only if there is a compelling reason.

See also[edit]