User Tools

Site Tools


devel:django_introduction

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
devel:django_introduction [2008/08/28 10:52]
morten fix typos
devel:django_introduction [2009/06/17 08:46]
jorabra Add missing word
Line 8: Line 8:
 ===== nav.django package ===== ===== nav.django package =====
  
-As NAV has not used Django from the very beginning, NAV does not strictly follow the Django convention of multiple apps with their own models, views, etc. To plug NAV into the Django framework some glue is needed. This glue and other common Django-related code is located in the ''​nav.django''​ Python package, which is located in ''​subsystem/​lib-python/src/​nav/​django''​.+As NAV has not used Django from the very beginning, NAV does not strictly follow the Django convention of multiple apps with their own models, views, etc. To plug NAV into the Django framework some glue is needed. This glue and other common Django-related code is located in the ''​nav.django''​ Python package, which is located in ''​subsystem/​lib-python/​nav/​django''​.
  
 ==== Settings ==== ==== Settings ====
Line 18: Line 18:
 ==== URL configuration ==== ==== URL configuration ====
  
-In ''​nav.django.urls''​ the root URL configuration for all things ​Django in NAV is located''​nav.django.urls''​ is not only a module, but also a package. The ''​%%__init__.py%%''​ file in the package imports all submodules it can find in the file system, calls ''​get_urlpatterns()''​ on all the submodules, and combines the results into one ''​urlpatterns''​ list, as all Django URL configurations does.+The root URL configuration for all Django-related applications ​in NAV is located ​in ''​nav.django.urls''​. It is not only a module, but also a package. The ''​%%__init__.py%%''​ file in the package imports all submodules it can find in the directory, calls ''​get_urlpatterns()''​ on all the submodules, and combines the results into one ''​urlpatterns''​ list, as all Django URL configurations does.
  
-In other words, when creating a new Django app in a branch of its ownyou simply drop a new submodule for your app into the ''​subsystem/​lib-python/​src/​nav/​django/​urls/''​ folder, run ''​make install''​ in ''​subsystem/​lib-python/​''​ and then the NAV installation will find your app. If somebody else runs ''​make install''​ in their version of ''​subsystem/​lib-python/​''​ they will not overwrite ​the URL configuration for your new app, unless they use exactly the same name for the submodule as you did.+When creating a new Django app, create ​a new submodule for your app in the ''​subsystem/​your_app/​nav/​django/​urls/''​ folder, run ''​make install''​ in your app to install the module into the ''​nav.django.urls'' ​package, ​and the NAV installation will find your app. If somebody else installs URLconf glue into ''​nav.django.urls''​ they will not affect ​the URL configuration for your app, unless they use exactly the same name for the submodule as you did. For details, check out the ''​ipdevinfo''​ subsystem and its ''​Makefile.in''​.
  
 === nav.django.urls.urlbuilder === === nav.django.urls.urlbuilder ===
  
-There is one special submodule named ''​nav.django.urls.urlbuilder''​. This is simply a Django replacement for the archaic ''​nav.web.urlbuilder''​. It is used by Django apps to link to non-Django apps, like the report subsystem, through the use of the ''​url''​ template tag or the ''​reverse()''​ function, instead of using the archaic ''​nav.web.urlbuilder''​. From your code's point of view, the URL configurations in ''​nav.django.urls.urlbuilder''​ is used as any other URL configuration in NAV.+There is one special submodule named ''​nav.django.urls.urlbuilder''​. This is simply a Django replacement for the archaic ''​nav.web.urlbuilder''​. It is used by Django apps to link to non-Django apps, like the report subsystem, through the use of the ''​url''​ template tag or the ''​reverse()''​ function, instead of using the archaic ''​nav.web.urlbuilder''​. From your code's point of view, the URL configurations in ''​nav.django.urls.urlbuilder''​ is used as any other Django ​URL configuration in NAV.
  
 ==== Shortcuts ==== ==== Shortcuts ====
Line 85: Line 85:
  
 Further, the file ''​ipdevinfo.tool''​ defines the name, description,​ icon and URL of the IP Device Info tool in NAV's toolbox. The file ''​htaccess''​ is the only file which is installed into the ''​ipdevinfo/''​ folder in the web server'​s document root. It simply states that all URLs starting with ''​http://​nav.example.com/​ipdevinfo/''​ are to be handled by a Python program, namely Django'​s mod_python handler, using ''​nav.django.settings''​ as configuration. In other words, the htaccess file should be identical for all Django apps in NAV. Further, the file ''​ipdevinfo.tool''​ defines the name, description,​ icon and URL of the IP Device Info tool in NAV's toolbox. The file ''​htaccess''​ is the only file which is installed into the ''​ipdevinfo/''​ folder in the web server'​s document root. It simply states that all URLs starting with ''​http://​nav.example.com/​ipdevinfo/''​ are to be handled by a Python program, namely Django'​s mod_python handler, using ''​nav.django.settings''​ as configuration. In other words, the htaccess file should be identical for all Django apps in NAV.
 +
 +Finally, the folder ''​media/''​ contains all static media which is needed by the app. Typically, this should be ''​media/​style/''​ for CSS-files, ''​media/​js/''​ for JavaScript, and ''​media/​images/''​ for images. Files should typically be named after the app to avoid name collisions with other apps when installed, i.e. ''​media/​style/​ipdevinfo.css''​ and subfolders like ''​media/​images/​ipdevinfo/''​.
 +
 +Configuration files should be in the ''​config/''​ folder in the source tree, and installed into ''​$NAVHOME/​etc/​appname/''​.
  
 How to install everything mentioned here is defined in ''​Makefile.in''​. How to install everything mentioned here is defined in ''​Makefile.in''​.
devel/django_introduction.txt ยท Last modified: 2010/01/13 11:30 by eide