Python Django

How To Use Django url Tag And reverse() Function To Avoid Url Hard Coded

Hard coded url in your Django template html files or views.py file is a bad practice. Because it is difficult to maintain url changes. If you change one url, you may need to change that url in a lot of pages. So Django provide template url tag and reverse function for you to avoid hard […]

How To Use Django url Tag And reverse() Function To Avoid Url Hard Coded Read More »

How To Pass Parameters To View Via Url In Django

Pass parameters via URL in Django is not as same as java or Php which use a question mark and key-value pairs ( for example http://127.0.0.1:8080/login.jsp?username=jerry&password=12345678). Django uses a more clear, readable, and SEO-friendly way to pass parameters in URL like http://127.0.0.1:8080/login/jerry/12345678. The first section after login is the username, and the section after jerry

How To Pass Parameters To View Via Url In Django Read More »

How To Retrieve Model Data Use get_list_or_404 And get_object_or_404 Shortcut Function

Django view is just a python function defined in the Django project / app_name / views.py file. The view function will receive and process user request ( generally get model data from backend database table ) and then return a HttpResponse object with a html template. The model data is passed back to the client

How To Retrieve Model Data Use get_list_or_404 And get_object_or_404 Shortcut Function Read More »

What Does Double Underscore ( __ ) Means In Django Model QuerySet Objects Filter Method

You have learnd how to use Django model manager’s filter or exclude method to get query result data in article Django Simple CRUD Operation Example. To use filter method is so easy as below. Department.objects.filter(dept_desc__contains=’dev2qa’) <QuerySet [<Department: Development,Develop dev2qa.com website use Django>]> We can see that the filter function’s argument is dept_desc__contains=’dev2qa’, i think this is not difficult

What Does Double Underscore ( __ ) Means In Django Model QuerySet Objects Filter Method Read More »