1

I cloned a sample app for django and run code inspection and found that admin.autodiscover is called before importing the views file, that's used for the patterns later:

from django.contrib import admin
from django.urls import path

admin.autodiscover()

import hello.views

urlpatterns = [
    path("", hello.views.index, name="index"),
    ...
]

This triggers a PEP8 code style warning as the imports are not all on the top of the file. I'm afraid that moving it may have unintended side effects. Is that the case?

  • No, it won't have side effects. Moreover, it's [no longer necessary at all](https://stackoverflow.com/a/12807691/3955830) since Django 1.8, so you can remove it completely. – solarissmoke Feb 16 '20 at 10:00

1 Answers1

1

According to docs you don't need to call the autodiscover function since django will call in when AdminConfig loads.

Glyphack
  • 876
  • 9
  • 20