1

I am running a dev server on localhost to test a django app. About a week ago the dev server started exiting on error- which is not ideal.

To give you an instance, imagine I want to create a new view, I make my template, then I add the following in urls:

urlpatterns = [
    ...
    path('forgotten-password', ForgottenPassword.as_view(), name='forgotten_password'),
]

I haven't yet created the ForgottenPassword class based view yet, so rightly the server throws the error:

File "/code/accounts/urls.py", line 19, in <module>
    path('forgotten-password', ForgottenPassword.as_view(), name='forgotten_password'),
NameError: name 'ForgottenPassword' is not defined

The server then quits however. This is not the desired behavior. I expect the server to remain in an error state until i fix the error (this happened up to about a week ago).

What causes this to happen, and how can i ensure that the dev server stays live on an error to avoid having to relaunch the entire app?

NB. It was around the same time that we upgraded from django 2.1 to 2.2, is this a desired behaviour in 2.2?

NB. II I am aware of this question in which a very similar problem is outlined, but I am running the dev server on ubuntu, not mac.

Update: Temporarily solved the problem by downgrading to django 2.1. Ticket opened here

Preston
  • 7,399
  • 8
  • 54
  • 84
  • There are [changes to runserver in 2.2](https://docs.djangoproject.com/en/2.2/releases/2.2/#management-commands) to refactor the code and use watchman. It sounds like this might be an (unexpected?) consequence of those changes. It might be worth [creating a ticket](https://code.djangoproject.com/) or asking on the [django-developers](https://docs.djangoproject.com/en/dev/internals/mailing-lists/#django-developers) mailing list. – Alasdair May 02 '19 at 13:33
  • @Alasdair will do! – Preston May 02 '19 at 13:40

2 Answers2

1

Looks like this was fixed in django 2.2.1, from the release notes:

Fixed a regression in Django 2.2 that caused a crash of runserver when URLConf modules raised exceptions (#30323).

Preston
  • 7,399
  • 8
  • 54
  • 84
0

Try to create URLs like this.

urls.py

from views import *

urlpatterns = [
        url(r'^forgotten-password/$', ForgottenPassword.as_view(), name='forgotten_password')
]

views.py

class ForgottenPassword(CreateView):
    template_name = 'forgotten-password.html'

    def get(self, request, *args, **kwargs):
        return render(request, self.template_name,{})

Miguel
  • 9
  • Thanks for the response, but the question is not about how to avoid the error (though i appreciate the thought), its about how to stop the dev server restarting. Like i say, i appreciate the help though – Preston May 02 '19 at 15:28