python - Import Error in django forms -


my django project file structure

  myproject        |--newsletter            |--__init__.py            |--admin.py            |--forms.py            |--models.py            |--tests.py            |--urls.py            |--views.py        |--myproject            |--settings.py            |--urls.py            |--wsgi.py         |--db.sqlite3        |--manage.py 

code in models.py

from django.db import models class signup(models.model):      email = models.emailfield()     first_name = models.charfield(max_length=120)     last_name = models.charfield(max_length=120, blank=true)     subscribtion_type_choices = (         ('w', 'weekly'),         ('m', 'monthly'),         ('y', 'yearly')     )     subscribtion_type = models.charfield(max_length=1, choices=subscribtion_type_choices)      def __str__(self):         return self.first_name 

code in admin.py

from django.contrib import admin newsletter.forms import signupform newsletter.models import signup  class signupadmin(admin.modeladmin):     # list_display = ('first_name', 'last_name', 'email', 'subscribtion_type')     form_signup = signupform  admin.site.register(signup, signupadmin) 

code in forms.py

from django import forms newsletter.models import signup  class signupform(forms.modelform):      class meta:         model = signup         fields = ['first_name', 'last_name', 'email', 'subscribtion_type', ] 

when hit ctrl+b in sublime text import error saying no module newsletter.models in form.py

traceback form.py

traceback (most recent call last):   file "/home/darshan99/django101/trydjango18/newsletter/forms.py", line 2, in <module>     newsletter.models import signup importerror: no module named newsletter.models [finished in 0.1s exit code 1] [shell_cmd: python -u "/home/darshan99/django101/trydjango18/newsletter/forms.py"] [dir: /home/darshan99/django101/trydjango18/newsletter] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games] 

traceback in admin.py

traceback (most recent call last):   file "/home/darshan99/django101/trydjango18/newsletter/admin.py", line 1, in <module>     django.contrib import admin   file "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 4, in <module>     django.contrib.admin.helpers import action_checkbox_name   file "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/helpers.py", line 8, in <module>     django.contrib.admin.utils import (   file "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/utils.py", line 7, in <module>     django.contrib.auth import get_permission_codename   file "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 7, in <module>     django.middleware.csrf import rotate_token   file "/usr/local/lib/python2.7/dist-packages/django/middleware/csrf.py", line 14, in <module>     django.utils.cache import patch_vary_headers   file "/usr/local/lib/python2.7/dist-packages/django/utils/cache.py", line 26, in <module>     django.core.cache import caches   file "/usr/local/lib/python2.7/dist-packages/django/core/cache/__init__.py", line 34, in <module>     if default_cache_alias not in settings.caches:   file "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__     self._setup(name)   file "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup     % (desc, environment_variable)) django.core.exceptions.improperlyconfigured: requested setting caches, settings not configured. must either define environment variable django_settings_module or call settings.configure() before accessing settings. [finished in 0.2s exit code 1] [shell_cmd: python -u "/home/darshan99/django101/trydjango18/newsletter/admin.py"] [dir: /home/darshan99/django101/trydjango18/newsletter] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games] 

just guess. try add . before newsletter imports in admin.py , forms.py, e. g.

from .newsletter.forms import signupform 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -