0

I'am using this maintenance-mode package https://github.com/fabiocaccamo/django-maintenance-mode in order to display my maintenance mode template. My template is displayed correctly but I am unable to add functions to this template.

I would like to add a function (ex. Subscription to Newsletter) to my maintenance mode template but I don't know where should I write my code. Because when the maintenance mode is On, my code from views.py is not used and my form is not displayed on my template.

Can anybody help me to find the way to add a function to my template when the maintenance mode is On?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Nikita
  • 75
  • 1
  • 10
  • The documentation says the template used is specified by the setting `MAINTENANCE_MODE_TEMPLATE`. Did you try editing that template, or setting it to point at your own preferred template? – James Bennett May 06 '18 at 10:06
  • Yes I configured `MAINTENANCE_MODE_TEMPLATE` and I my template is displayed correctly. My problem is that my code `form = Interstedform(request.POST) if form.is_valid(): form.save()` is not used – Nikita May 06 '18 at 10:17
  • Therefore I have HTML which can't save email to my database. – Nikita May 06 '18 at 10:20
  • 2
    The point of maintenance mode is that you can't and don't run any view code. You only get whatever's in your (mostly static) template. – James Bennett May 06 '18 at 11:02

1 Answers1

1

I agree with James' comment. You miss the point of the maintenance mode. Put your web app in the maintenance mode when you want to upgrade some libraries or deploy a new version of the web app.

  • maintenance mode on
  • upgrade/deployment
  • maintenance mode off

If your deployment process is good, you will spend no more then a few minutes in the maintenance mode. During that time you don't need any view to be executed. Especially if it ends with some records in the database.

However, if you really must to execute some function, you need to move it in middleware https://docs.djangoproject.com/en/2.0/topics/http/middleware/. Just be sure that your middleware is executed before maintenance middleware.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Goran
  • 6,644
  • 11
  • 34
  • 54