For a newbie, understanding the working of Django framework and importance of each file in the application is quite difficult. When making an application one need to have following things:
- Django & MySQL installed.
- Apache configured with application.
- Basic knowledge and understanding of Python.
When building a module in an application one should have understanding on functioning in each file is dependent on other. When we create an application, the files created are :
In addition to these files, we can add other files too according to the need. The functioning of each file can be explained through the example given below :
When we want to add a module to our application, the first thing we would like to see is menu option which is visible to us, which is linked through a url. Like here I am going to add a client register to my application. So, for that we need have a menu option named ‘client register’.
This can be done by adding the following code in your index.html file or any other template where you want menu option :
<li><a href=”/automation/tcc/clientregister”>Client Register</a></li>
As we have linked the option with some url address thus we need to define this url in urls.py. Here comes the role of urls.py file. The code in urls file goes as follows :
Here ‘r’ means regular expression that matches the url and then points it to some function defined in file (e.g. views.py, register.py). When the url on the browser matches with the regular expression that is red circled, it will then call the function ‘client_register’ defined in register.py file. Thus, now we need to define a function ‘client_register’ in register.py file(in my case) or views.py file.
The code for register.py file goes as follows :