python - Architecture of a Django project -


i have started learning django , having confusion regarding architecture of django project.

basically want know recommended way design django application ie: type of code put in models file, views file , write validators etc.

as example, suppose while creating registration form add new user want make sure user not register username present in database. per observation there 3 ways it.

  1. i define method in models.py file , call after getting data form.
  2. i define method in views.py file , call method.
  3. i write custom validator or clean method in forms.py file.

as beginner confused per approach best. basic set of rules follow can me decide type of code written me. thanks

unsurprisingly, general recommendation put view code in views.py, model code in models.py , form code in forms.py.

you have ability put code more or less wherever want it, better off sticking these recommendations beginner.

since want sure added user isn't in database best handled in view code, there's nothing in principle wrong using model method check new save()s duplication. it's matter of whether functionality required anywhere else.

matters of application architecture can difficult newcomers. recommendations in book "two scoops of django" embody many best practices.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -