1

I am using django 1.10.5, and mongodb in project backend. My project structure is as follow-

project_name
|-- applications
|   |-- app1
|   |   |-- admin.py
|   |   |-- upload.py
|   |   |-- __init__.py
|   |   |-- migrations
|   |   |   `-- __init__.py
|   |   |-- models.py
|   |   |-- services.py
|   |   |-- urls.py
|   |   |-- views.py
|   |-- __init__.py
|-- __init__.py
|-- manage.py
|-- project_name_config
    |-- __init__.py
    |-- settings
    |   |-- dev_settings.py
    |   |-- __init__.py
    |   |-- prod_settings.py
    |   |-- settings.py
    |-- urls.py
    |`-- wsgi.py

I am using virtual environment. I have created app using manage.py under directory applications. As per django tutorials when I have added app_name under INSTALLED_APPS list in settings.py, as-

    INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'applications.app1',
]

it is giving error as-

(virtEnv):~$python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x7fe94e554848>
Traceback (most recent call last):File "/home/dir_project/virtEnv/local/lib/python2.7/site-  packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
  File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
  File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
  File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
 File "/home/dir_project/virtEnv/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in  import_module
__import__(name)
ImportError: No module named app1

But when I removed app_name from settings.py my application, views etc everything is working.

Considering future scope, is it mandatory to add app_name in settings.py under INSTALLED_APPS list.

Thanks in advance.

sachin27
  • 145
  • 3
  • 13

1 Answers1

1

In order to get your models to be created as tables in DB or if we want to write any custom template tags and make them work, it is mandatory we keep our app_name in INSTALLED_APPS. As your actual application app1 is in applications folder keep applications.app1 in your INSTALLED_APPS rather than just app1

MicroPyramid
  • 1,570
  • 19
  • 22
  • Thanks for reply. When I added applications.app1 in settings.py, it is now giving error as, ImportError: No module named project_name.applications.app1.apps – sachin27 Feb 01 '17 at 11:55
  • I can't see vshare.applications.articleApp.apps this path in the project structure. Can you update your project structure? And also can you check if you have used vshare.applications.articleApp.apps in any of your files? – MicroPyramid Feb 01 '17 at 12:00
  • Error is as, ImportError: No module named project_name.applications.app1.apps – sachin27 Feb 01 '17 at 12:51
  • Can you update your new INSTALLED_APPS in the question? – MicroPyramid Feb 02 '17 at 01:58