Shivling : Avoiding boilerplate in views in Django
I have been unable to find time to continue my Shiv series, however, a chat with a friend(@arihersh) who has just started learning django reminded me of a small piece of code I had written sometime back. The chat went something like this
At first I suggested Shiv to make the views more modular, but it was kinda overkill for the particular project. Then I remembered a piece of code that I had written well after Shiv which can be viewed as a motivation for Shiv (though it was written after Shiv).
This is for ajax views. Its almost identical to the one in Shiv. You will need to create a url entry in urls.py and follow some sort of url pattern so that the registered name can be passed.
Every ajax view contains a key member (func.key) which can be used to generate the desired url. You can look at the ajax_view function below to understand how the required view is called.
This is where the main action happens. There are two kind of functions here. The ones which are called by urls.py directly and the other which are used by the first one to create the response.
And the html can create a hidden element like
Next, I will get back to talking more about Shiv. I hope the above helps in explaining the reason I started writing Shiv.