Enable not defined

To clarify security, this is the project folder, and Accounts is the application. I am sure this is an elementary problem that I am missing, but I tried my best to get my manged.py commands to work, because the following error:

NameError: the name 'include' is not defined.

My project (Security) urls.py is as follows: it has:

from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^account/', include('accounts.url')), ] 

My apps.py accounts contains:

 from django.apps import AppConfig class AccountsConfig(AppConfig): name = 'accounts' 

The application of my urls.py accounts is as follows:

  from django.conf.urls import url, include from . import views urlpatterns = [ url(r'^$', views.home, name='home'), ] 

My .py settings have accounts in installed applications:

 INSTALLED_APPS = [ 'accounts', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 

After adding include to both urls.py for my project and application, now I welcome the next account module, which was not found.

  return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked ModuleNotFoundError: No module named 'accounts.url' 
0
python django
Sep 11 '17 at 14:57
source share
4 answers

You use the include function in a file in which you do not import it. You must add

 from django.conf.urls import url, include 

into your urls.py security application

EDIT

For the second error, try changing the way you include URLs from accounts. Replace accounts.url for this relative path, starting from the application folder. for example

 url(r'^account/', include('accounts.urls')), 

If in doubt, add the folder structure to the question and I will update the answer correctly.

+1
Sep 11 '17 at 2:59
source share
 In your rootapp.py you have used urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^account/', include('accounts.url')), ] Here you have used include('accounts.url') But you have not imported include So your code should be from django.apps import AppConfig class AccountsConfig(AppConfig): name = 'accounts' my security app urls.py is the following: from django.conf.urls import url , include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^account/', include('accounts.url')), ] 
0
Sep 11 '17 at 15:01
source share

Here is the solution:

 from django.conf.urls import include 

import it into the urls.py page of your project.

0
Aug 19 '19 at 21:44
source share

Hi, I'm not sure, but it works for me. I just installed the include module with this command (in a virtual environment):

pip install include

The script no longer displays an error.

0
Aug 23 '19 at 8:13
source share



All Articles