gpt4 book ai didi

python - 导入错误(无法导入姓名 contactForm )

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:14 25 4
gpt4 key购买 nike

我正在尝试构建一个 e_commerc django 应用程序,但我遇到了一个错误,而且有点令人困惑。我的错误是:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.7.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'profiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template /home/petarp/Documents/Udemy/Learn_Django/static/templates/navbar.html, error at line 15
cannot import name contactForm
5 : <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
6 : <span class="sr-only">Toggle navigation</span>
7 : <span class="icon-bar"></span>
8 : <span class="icon-bar"></span>
9 : <span class="icon-bar"></span>
10 : </button>
11 : <a class="navbar-brand" href="#">Bootstrap theme</a>
12 : </div>
13 : <div id="navbar" class="navbar-collapse collapse">
14 : <ul class="nav navbar-nav">
15 : {% url 'home' as home %}
16 : {% url 'about' as about %}


17 : {% url 'contact' as contact %}
18 : <li {% if request.path == home %} class="active" {%endif%}><a href="{% url 'home' %}">Home</a></li>
19 : <li {% if request.path == about %} class="active" {%endif%}><a href="{% url 'about' %}">About</a></li>
20 : <li {% if request.path == contact %} class="active" {%endif%}><a href="{% url 'contact' %}">Contact</a></li>
21 : <li class="dropdown">
22 : <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
23 : <ul class="dropdown-menu" role="menu">
24 : <li><a href="#">Action</a></li>
25 : <li><a href="#">Another action</a></li>
Traceback:
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/petarp/Documents/Udemy/Learn_Django/source/profiles/views.py" in home
7. return render(request, tempalte, context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/shortcuts.py" in render
50. return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
178. return t.render(context_instance)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in render
148. return self._render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in _render
142. return self.nodelist.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
126. return compiled_parent._render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in _render
142. return self.nodelist.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
150. return template.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in render
148. return self._render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in _render
142. return self.nodelist.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/base.py" in render
844. bit = self.render_node(node, context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
80. return node.render(context)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
444. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
551. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
415. self._populate()
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
303. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
231. self._callback = get_callable(self._callback_str)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/utils/lru_cache.py" in wrapper
101. result = user_function(*args, **kwds)
File "/home/petarp/.virtualenvs/e_udemy/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
97. mod = import_module(mod_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/petarp/Documents/Udemy/Learn_Django/source/contact/views.py" in <module>
3. from .forms import contactForm

Exception Type: ImportError at /
Exception Value: cannot import name contactForm

我不明白这个错误,或者更好地说我看不到这个错误。这是我的views.pyforms.py 。为什么他不能导入contactForm?有人可以解释一下我该如何克服这个问题。保护你。

最佳答案

我认为你在 forms.py 中犯了一个错误。

请确保您正确拼写了 contactForm 函数。在 contactForm 中,F 必须大写。

class contactForm(forms.Form):

关于python - 导入错误(无法导入姓名 contactForm ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28555202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com