Dodałem do pliku forms.py drugi formularz i wyskakuje mi błąd :/
cannot import name FormularzPasswordChange
forms.py
I add to forms.py another Form "FormularzPasswordChange"
forms.py
views.py
My Bug is:
-- cannot import name FormularzPasswordChange
forms.py
I add to forms.py another Form "FormularzPasswordChange"
and I receive a error like belowforms.py
# -*- coding: utf-8 -*-
import re
from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.models import User
class FormularzRejestracji(forms.Form):
username = forms.CharField(label="Login:",max_length=30)
email = forms.EmailField(label="Email:")
password1 = forms.CharField(label="Hasło:",widget=forms.PasswordInput())
password2 = forms.CharField(label="Powtórz hasło:",widget=forms.PasswordInput())
log_on = forms.BooleanField(label="Logowanie po rejestracji:",required=False)
def clean_password2(self):
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
else:
raise forms.ValidationError("Hasła się różnią")
def clean_username(self):
username = self.cleaned_data['username']
if not re.search(r'^\w+$',username):
raise forms.ValidationError("Dopuszczalne są tylko cyfry, litery angielskie i _ ")
try:
User.objects.get(username = username)
except ObjectDoesNotExist:
return username
raise forms.ValidationError("Taki użytkownik już istnieje")
class FormularzPasswordChange(forms.Form):
password1 = forms.CharField(label="Hasło:",widget=forms.PasswordInput())
password2 = forms.CharField(label="Powtórz hasło:",widget=forms.PasswordInput())
def clean_password2(self):
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
else:
raise forms.ValidationError("Hasła się różnią")
views.py
# -*- coding: utf-8 -*-
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext, loader
from django.contrib.auth import logout,login,authenticate
from dom.forms import FormularzRejestracji, FormularzPasswordChange
from django.contrib.auth.models import User
def index(request):
template = loader.get_template('registration/index.html')
context = RequestContext(request, {
})
return HttpResponse(template.render(context))
def logout_dom(request):
logout(request)
return HttpResponseRedirect("/")
def register_dom(request):
if request.method == 'POST':
form = FormularzRejestracji(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
email=form.cleaned_data['email'],
)
user.save()
if form.cleaned_data['log_on']: # gdy zalogowany jestes
user = authenticate(username=form.cleaned_data['username'],password=form.cleaned_data['password1'])
login(request,user)
template = loader.get_template("registration/index.html")
variables = RequestContext(request,{'user':user})
output = template.render(variables)
return HttpResponseRedirect("/")
else:
template = loader.get_template("registration/register_success.html")
variables = RequestContext(request,{'username':form.cleaned_data['username']})
output = template.render(variables)
return HttpResponse(output)
else:
form = FormularzRejestracji()
template = loader.get_template('registration/register.html')
variables = RequestContext(request,{'form':form})
output = template.render(variables)
return HttpResponse(output)
def password_change(request):
if request.method == 'POST':
form = FormularzPasswordChange(request.POST)
if form.is_valid():
user = User.objects.get(username='username')
user.set_password(form.cleaned_data['password2']),
user.save()
else:
form = FormularzPasswordChange()
template = loader.get_template('registration/change_password.html')
variables = RequestContext(request,{'form':form})
output = template.render(variables)
return HttpResponse(output)
My Bug is:
ImportError at /
cannot import name FormularzPasswordChange
Request Method: GET
Request URL: http://darmys.pythonanywhere.com/
Django Version: 1.6.5
Exception Type: ImportError
Exception Value:
cannot import name FormularzPasswordChange
Exception Location: /home/darmys/dom/dom/views.py in <module>, line 8
Python Executable: /usr/local/bin/uwsgi
Python Version: 2.7.5
Python Path:
['/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
'/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages',
'/var/www',
'.',
'',
'/usr/local/lib/python2.7/dist-packages/setuptools-5.4.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/snappy-2.2-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/cypari-1.1-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/spherogram-1.3-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/pypng-0.0.17-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/plink-1.7-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/decorator-3.4.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/Orange_Text-1.2a1-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/Orange-2.7.5-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/backports.ssl_match_hostname-3.4.0.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/certifi-14.05.14-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/pyhdf-0.8.3-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages/texcaller-0-py2.7-linux-x86_64.egg',
'/usr/local/lib/python2.7/dist-packages',
'/var/www',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/pymodules/python2.7',
'/home/darmys/dom']
Server time: Pt, 26 Wrze 2014 03:55:21 +0000
Traceback Switch to copy-and-paste view
/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
resolver_match = resolver.resolve(request.path_info)
...
▶ Local vars
/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/django/core/urlresolvers.py in resolve
for pattern in self.url_patterns:
...
▶ Local vars
/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/django/core/urlresolvers.py in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
...
▶ Local vars
/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/django/core/urlresolvers.py in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
...
▶ Local vars
/home/darmys/.virtualenvs/django16/lib/python2.7/site-packages/django/utils/importlib.py in import_module
__import__(name)
...
▶ Local vars
/home/darmys/dom/dom/urls.py in <module>
from dom import views
...
▶ Local vars
/home/darmys/dom/dom/views.py in <module>
from dom.forms import FormularzRejestracji, FormularzPasswordChange
...
▶ Local vars
Request information
GET
No GET data
POST
No POST data
FILES
No FILES data
COOKIES
Variable Value
csrftoken
'GXfxMMC5SKvK5negTmFYnezLOJsMlq1e'
__utma
'133430031.1623745599.1411155068.1411667925.1411675006.10'
__utmz
'133430031.1411155068.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)'
sessionid
'my7z9n75seg2wi7esaiuuecthzpxjscj'
META
Variable Value
wsgi.multiprocess
False
HTTP_COOKIE
'__utma=133430031.1623745599.1411155068.1411667925.1411675006.10; __utmz=133430031.1411155068.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); csrftoken=GXfxMMC5SKvK5negTmFYnezLOJsMlq1e; sessionid=my7z9n75seg2wi7esaiuuecthzpxjscj'
uwsgi.version
'2.0.5.1'
SCRIPT_NAME
u''
REQUEST_METHOD
'GET'
PATH_INFO
u'/'
SERVER_PROTOCOL
'HTTP/1.1'
QUERY_STRING
''
HTTP_X_REAL_IP
'91.149.225.65'
CONTENT_LENGTH
''
HTTP_USER_AGENT
'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'
HTTP_CONNECTION
'close'
SERVER_NAME
'darmys.pythonanywhere.com'
REMOTE_ADDR
'10.138.64.83'
wsgi.url_scheme
'http'
SERVER_PORT
'80'
uwsgi.node
'giles-liveweb3'
DOCUMENT_ROOT
'/usr/local/openresty/nginx/html'
wsgi.input
<uwsgi._Input object at 0x26f3e40>
HTTP_HOST
'darmys.pythonanywhere.com'
wsgi.multithread
False
REQUEST_URI
'/'
HTTP_ACCEPT
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
wsgi.version
(1, 0)
HTTP_X_FORWARDED_FOR
'91.149.225.65'
wsgi.errors
<uwsgi_file__bin_user_wsgi_wrapper.ErrorLogFile object at 0x20ee110>
REMOTE_PORT
'58935'
HTTP_ACCEPT_LANGUAGE
'pl,en-US;q=0.7,en;q=0.3'
wsgi.run_once
False
CONTENT_TYPE
''
wsgi.file_wrapper
''
HTTP_ACCEPT_ENCODING
'gzip, deflate'
Settings
Using settings module dom.settings
Setting Value
USE_L10N
True
USE_THOUSAND_SEPARATOR
False
CSRF_COOKIE_SECURE
False
LANGUAGE_CODE
'pl'
ROOT_URLCONF
'dom.urls'
MANAGERS
()
BASE_DIR
'/home/darmys/dom'
DEFAULT_CHARSET
'utf-8'
SESSION_SERIALIZER
'django.contrib.sessions.serializers.JSONSerializer'
STATIC_ROOT
'/home/darmys/dom/static'
ALLOWED_HOSTS
[]
MESSAGE_STORAGE
'django.contrib.messages.storage.fallback.FallbackStorage'
EMAIL_SUBJECT_PREFIX
'[Django] '
FILE_UPLOAD_PERMISSIONS
None
STATICFILES_FINDERS
('django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder')
SESSION_CACHE_ALIAS
'default'
SESSION_COOKIE_DOMAIN
None
SESSION_COOKIE_NAME
'sessionid'
ADMIN_FOR
()
TIME_INPUT_FORMATS
('%H:%M:%S', '%H:%M:%S.%f', '%H:%M')
DATABASES
{'default': {'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'ENGINE': 'django.db.backends.mysql',
'HOST': 'mysql.server',
'NAME': 'darmys$db1',
'OPTIONS': {},
'PASSWORD': u'********************',
'PORT': '',
'TEST_CHARSET': None,
'TEST_COLLATION': None,
'TEST_MIRROR': None,
'TEST_NAME': None,
'TIME_ZONE': 'UTC',
'USER': 'darmys'}}
SERVER_EMAIL
'root@localhost'
FILE_UPLOAD_HANDLERS
('django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler')
DEFAULT_CONTENT_TYPE
'text/html'
APPEND_SLASH
True
FIRST_DAY_OF_WEEK
0
DATABASE_ROUTERS
[]
YEAR_MONTH_FORMAT
'F Y'
STATICFILES_STORAGE
'django.contrib.staticfiles.storage.StaticFilesStorage'
CACHES
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
SESSION_COOKIE_PATH
'/'
MIDDLEWARE_CLASSES
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
USE_I18N
True
THOUSAND_SEPARATOR
','
SECRET_KEY
u'********************'
LANGUAGE_COOKIE_NAME
'django_language'
DEFAULT_INDEX_TABLESPACE
''
TRANSACTIONS_MANAGED
False
LOGGING_CONFIG
'django.utils.log.dictConfig'
SEND_BROKEN_LINK_EMAILS
False
TEMPLATE_LOADERS
('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')
WSGI_APPLICATION
'dom.wsgi.application'
TEMPLATE_DEBUG
True
X_FRAME_OPTIONS
'SAMEORIGIN'
CSRF_COOKIE_NAME
'csrftoken'
FORCE_SCRIPT_NAME
None
USE_X_FORWARDED_HOST
False
SIGNING_BACKEND
'django.core.signing.TimestampSigner'
SESSION_COOKIE_SECURE
False
CSRF_COOKIE_DOMAIN
None
FILE_CHARSET
'utf-8'
DEBUG
True
SESSION_FILE_PATH
None
DEFAULT_FILE_STORAGE
'django.core.files.storage.FileSystemStorage'
INSTALLED_APPS
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'player')
LANGUAGES
(('af', 'Afrikaans'),
('ar', 'Arabic'),
('az', 'Azerbaijani'),
('bg', 'Bulgarian'),
('be', 'Belarusian'),
('bn', 'Bengali'),
('br', 'Breton'),
('bs', 'Bosnian'),
('ca', 'Catalan'),
('cs', 'Czech'),
('cy', 'Welsh'),
('da', 'Danish'),
('de', 'German'),
('el', 'Greek'),
('en', 'English'),
('en-gb', 'British English'),
('eo', 'Esperanto'),
('es', 'Spanish'),
('es-ar', 'Argentinian Spanish'),
('es-mx', 'Mexican Spanish'),
('es-ni', 'Nicaraguan Spanish'),
('es-ve', 'Venezuelan Spanish'),
('et', 'Estonian'),
('eu', 'Basque'),
('fa', 'Persian'),
('fi', 'Finnish'),
('fr', 'French'),
('fy-nl', 'Frisian'),
('ga', 'Irish'),
('gl', 'Galician'),
('he', 'Hebrew'),
('hi', 'Hindi'),
('hr', 'Croatian'),
('hu', 'Hungarian'),
('ia', 'Interlingua'),
('id', 'Indonesian'),
('is', 'Icelandic'),
('it', 'Italian'),
('ja', 'Japanese'),
('ka', 'Georgian'),
('kk', 'Kazakh'),
('km', 'Khmer'),
('kn', 'Kannada'),
('ko', 'Korean'),
('lb', 'Luxembourgish'),
('lt', 'Lithuanian'),
('lv', 'Latvian'),
('mk', 'Macedonian'),
('ml', 'Malayalam'),
('mn', 'Mongolian'),
('my', 'Burmese'),
('nb', 'Norwegian Bokmal'),
('ne', 'Nepali'),
('nl', 'Dutch'),
('nn', 'Norwegian Nynorsk'),
('os', 'Ossetic'),
('pa', 'Punjabi'),
('pl', 'Polish'),
('pt', 'Portuguese'),
('pt-br', 'Brazilian Portuguese'),
('ro', 'Romanian'),
('ru', 'Russian'),
('sk', 'Slovak'),
('sl', 'Slovenian'),
('sq', 'Albanian'),
('sr', 'Serbian'),
('sr-latn', 'Serbian Latin'),
('sv', 'Swedish'),
('sw', 'Swahili'),
('ta', 'Tamil'),
('te', 'Telugu'),
('th', 'Thai'),
('tr', 'Turkish'),
('tt', 'Tatar'),
('udm', 'Udmurt'),
('uk', 'Ukrainian'),
('ur', 'Urdu'),
('vi', 'Vietnamese'),
('zh-cn', 'Simplified Chinese'),
('zh-tw', 'Traditional Chinese'))
COMMENTS_ALLOW_PROFANITIES
False
STATICFILES_DIRS
()
PREPEND_WWW
False
SECURE_PROXY_SSL_HEADER
None
SESSION_COOKIE_HTTPONLY
True
DEBUG_PROPAGATE_EXCEPTIONS
False
MONTH_DAY_FORMAT
'F j'
LOGIN_URL
'/accounts/login/'
SESSION_EXPIRE_AT_BROWSER_CLOSE
False
TIME_FORMAT
'P'
AUTH_USER_MODEL
'auth.User'
DATE_INPUT_FORMATS
('%Y-%m-%d',
'%m/%d/%Y',
'%m/%d/%y',
'%b %d %Y',
'%b %d, %Y',
'%d %b %Y',
'%d %b, %Y',
'%B %d %Y',
'%B %d, %Y',
'%d %B %Y',
'%d %B, %Y')
AUTHENTICATION_BACKENDS
('django.contrib.auth.backends.ModelBackend',)
EMAIL_HOST_PASSWORD
u'********************'
PASSWORD_RESET_TIMEOUT_DAYS
u'********************'
CACHE_MIDDLEWARE_ALIAS
'default'
SESSION_SAVE_EVERY_REQUEST
False
NUMBER_GROUPING
0
SESSION_ENGINE
'django.contrib.sessions.backends.db'
CSRF_FAILURE_VIEW
'django.views.csrf.csrf_failure'
CSRF_COOKIE_PATH
'/'
LOGIN_REDIRECT_URL
'/accounts/profile/'
DECIMAL_SEPARATOR
'.'
IGNORABLE_404_URLS
()
LOCALE_PATHS
()
TEMPLATE_STRING_IF_INVALID
''
LOGOUT_URL
'/accounts/logout/'
EMAIL_USE_TLS
False
FIXTURE_DIRS
()
EMAIL_HOST
'localhost'
DATE_FORMAT
'N j, Y'
MEDIA_ROOT
''
DEFAULT_EXCEPTION_REPORTER_FILTER
'django.views.debug.SafeExceptionReporterFilter'
ADMINS
()
FORMAT_MODULE_PATH
None
DEFAULT_FROM_EMAIL
'webmaster@localhost'
MEDIA_URL
''
DATETIME_FORMAT
'N j, Y, P'
TEMPLATE_DIRS
()
DISALLOWED_USER_AGENTS
()
ALLOWED_INCLUDE_ROOTS
()
LOGGING
{}
SHORT_DATE_FORMAT
'm/d/Y'
TEST_RUNNER
'django.test.runner.DiscoverRunner'
CACHE_MIDDLEWARE_KEY_PREFIX
u'********************'
TIME_ZONE
'UTC'
FILE_UPLOAD_MAX_MEMORY_SIZE
2621440
EMAIL_BACKEND
'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_TABLESPACE
''
TEMPLATE_CONTEXT_PROCESSORS
('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages')
SESSION_COOKIE_AGE
1209600
SETTINGS_MODULE
'dom.settings'
USE_ETAGS
False
LANGUAGES_BIDI
('he', 'ar', 'fa', 'ur')
FILE_UPLOAD_TEMP_DIR
None
INTERNAL_IPS
()
STATIC_URL
'/static/'
EMAIL_PORT
25
USE_TZ
True
SHORT_DATETIME_FORMAT
'm/d/Y P'
PASSWORD_HASHERS
u'********************'
ABSOLUTE_URL_OVERRIDES
{}
CACHE_MIDDLEWARE_SECONDS
600
CSRF_COOKIE_HTTPONLY
False
DATETIME_INPUT_FORMATS
('%Y-%m-%d %H:%M:%S',
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M',
'%Y-%m-%d',
'%m/%d/%Y %H:%M:%S',
'%m/%d/%Y %H:%M:%S.%f',
'%m/%d/%Y %H:%M',
'%m/%d/%Y',
'%m/%d/%y %H:%M:%S',
'%m/%d/%y %H:%M:%S.%f',
'%m/%d/%y %H:%M',
'%m/%d/%y')
EMAIL_HOST_USER
''
PROFANITIES_LIST
u'********************'
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 500 page.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/40619a12-aee5-44f0-b65a-f1079cdc7166%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment