Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango custom form ImportError even though file is in the same directory
    primarykey
    data
    text
    <p>I'm working through <a href="http://effectivedjango.com/" rel="nofollow">Effective Django's</a> tutorial series. I'm currently having an issue trying to create a custom form to use in an app. I created the forms.py file as instructed in <a href="http://effectivedjango.com/tutorial/forms.html" rel="nofollow">this part of the tutorial</a>, and made the alterations to my views.py file. My directory structure looks like this: </p> <pre><code>(project root) | ├── address.db ├── addressbook │   ├── __init__.py │   ├── __pycache__ │   ├── settings.py │   ├── static │   ├── urls.py │   └── wsgi.py ├── contacts │   ├── __init__.py │   ├── admin.py │   ├── forms.py │   ├── models.py │   ├── templates │   ├── tests.py │   └── views.py ├── manage.py └── requirements.txt </code></pre> <p>The problem is that when I try to load the site I get the following error:</p> <pre><code>Traceback (most recent call last): File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/handlers/base.py", line 101, in get_response resolver_match = resolver.resolve(request.path_info) File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/urlresolvers.py", line 318, in resolve for pattern in self.url_patterns: File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/urlresolvers.py", line 346, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/urlresolvers.py", line 341, in urlconf_module self._urlconf_module = import_module(self.urlconf_name) File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/importlib/__init__.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "&lt;frozen importlib._bootstrap&gt;", line 1586, in _gcd_import File "&lt;frozen importlib._bootstrap&gt;", line 1567, in _find_and_load File "&lt;frozen importlib._bootstrap&gt;", line 1534, in _find_and_load_unlocked File "&lt;frozen importlib._bootstrap&gt;", line 586, in _check_name_wrapper File "&lt;frozen importlib._bootstrap&gt;", line 1024, in load_module File "&lt;frozen importlib._bootstrap&gt;", line 1005, in load_module File "&lt;frozen importlib._bootstrap&gt;", line 562, in module_for_loader_wrapper File "&lt;frozen importlib._bootstrap&gt;", line 870, in _load_module File "&lt;frozen importlib._bootstrap&gt;", line 313, in _call_with_frames_removed File "/Users/wtodom/.virtualenvs/tutorial/addressbook/urls.py", line 4, in &lt;module&gt; import contacts.views File "/Users/wtodom/.virtualenvs/tutorial/contacts/views.py", line 5, in &lt;module&gt; import forms ImportError: No module named 'forms' </code></pre> <p>Line 5 is the line in views.py where I import the forms.py file. The code snippet (with a few lines of buffer) is:</p> <pre><code>from django.shortcuts import render from django.views.generic import ListView, CreateView, UpdateView, DeleteView, DetailView from django.core.urlresolvers import reverse from contacts.models import Contact import forms class ListContactView(ListView): model = Contact template_name = 'contact_list.html' </code></pre> <p>As you can see from the directory tree, the forms.py file should be accessible. I'm not sure why I'm getting the error. Any ideas?</p> <h3>Edit 1</h3> <p>I tried changing the import to <code>from forms import ContactForm</code> before posting originally. I still got the same error:</p> <pre><code> File "/Users/wtodom/.virtualenvs/tutorial/contacts/views.py", line 5, in &lt;module&gt; from forms import ContactForm ImportError: No module named 'forms' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload