[Django]-Optimized way of passing a form in all view functions django

1👍

If you can want to use this form in django templates(every) you must write context processors:
Please read this links:

https://docs.djangoproject.com/en/1.10/_modules/django/template/context_processors/

https://docs.djangoproject.com/en/1.10/ref/templates/api/#writing-your-own-context-processors

2👍

As @Mubariz Feyziyev mentioned, you can use context processors to render your form in each template. This is one way to this. Additionally,

If you are OK with not using django forms:

  • Create your form with pure html on client side,
  • Set its action value to a particular url like /api/handle-my-nice-form,
  • Create a view that handles this form’s request and connect it to url record (/api/handle-my-nice-form/)

If you are new to Django, You should use built-in forms. But as your app grows and gets complicated or if you decided to use a library like React or Angular; it might be better building an api based system to handle this kind of stuff.

Leave a comment