Not able to create user profile using django-registration - django

I am using django-registration app. I am trying to create a social networking website. I am a newbie to website development. Here is the error I am getting:
Environment:
Request Method: POST
Request URL: 127.0.0.1:8000/accounts/register/
Django Version: 1.4.2
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'registration_defaults',
'django.contrib.admin',
'registration',
'polls')
Installed Middleware:
('django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/registration/views.py" in register
187. new_user = backend.register(request, **form.cleaned_data)
File "/Library/Python/2.7/site-packages/registration/backends/default/__init__.py" in register
79. password, site)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
209. return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/registration/models.py" in create_inactive_user
78. new_user = User.objects.create_user(username, email, password)
File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py" in create_user
160. user.save(using=self._db)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
565. created=(not record_exists), raw=raw, using=using)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py" in send
172. response = receiver(signal=self, sender=sender, **named)
File "/Users/dineshsingh/Desktop/django/mysite/users/models.py" in create_user_profile
20. UserProfile.objects.create(user=instance)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in create
137. return self.get_query_set().create(**kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in create
377. obj.save(force_insert=True, using=self.db)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in insert_query
1593. return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
910. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute
40. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
344. return Database.Cursor.execute(self, query, params)
Exception Type: DatabaseError at /accounts/register/
Exception Value: no such table: users_userprofile
Any help will be highly appreciated.

According to the Error stack, I think you are doing it in the wrong manner.
It may be that you are creating an app named `users` which is not required here.
Here is the step by step process how to use django-registration.
After installing django-registration we need to add it in the settings.py file to make sure that our django engine reads it and loads it.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'registration', #<--Here I have added
)
Now You need to add a few more settings in the settngs.py file:
ACCOUNT_ACTIVATION_DAYS = 2
EMAIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'webmaster#localhost'
LOGIN_REDIRECT_URL = '/'
Now update the urls.py file to send all the /accounts/ request to the django-registration app.
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
...
(r'^accounts/', include('registration.urls')),
...
)
Now you need to create some templates to support your django-registration.
login.html — user login form
logout.html — shown after a user has logged out
password_change_form.html — password change form
password_change_done.html — shown after successful password change
password_reset_form.html — ask user for email to send password-reset mail to
password_reset_email.html — template for password-reset mail
password_reset_done.html — shown after password-reset email has been sent
password_reset_confirm.html — ask user for new password after reset
password_reset_complete.html — shown after successful password reset
registration_form.html — user registration form
registration_complete.html — shown after a user has registered
activation_email_subject.txt — subject of activation email
activation_email.txt — template for activation email
activate.html — shown after a user has activated his account
A basic model that what you need to put in these files can be #the-django-registration-git-hub-link
Now I hope you can get it running.
Few more link to check out.
Link 1
Link 2

Do you have right AUTH_PROFILE_MODULE in your settings.py?
That seems it should be:
AUTH_PROFILE_MODULE = 'registration.RegistrationProfile'

Related

user_change_password() got an unexpected keyword argument 'extra_context'

Django 3.0.7
When I try to change password in admin site, I get
TypeError at /admin/auth/user/1/password/
user_change_password() got an unexpected keyword argument 'extra_context'
Namely I pressed "this form" link:
More details
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/password/
Django Version: 3.0.7
Python Version: 3.8.0
Installed Applications:
['admin_aux',
'images.apps.ImagesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'posts',
'sidebars',
'general',
'categories',
'marketing',
'home',
'authors',
'taggit',
'cachalot',
'django_cleanup.apps.CleanupConfig',
'widgets',
'code_samples',
'hyper_links',
'polls',
'applications',
'videos',
'quotations',
'languages',
'people',
'arbitrary_htmls.apps.ArbitraryHtmlsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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']
Traceback (most recent call last):
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
Exception Type: TypeError at /admin/auth/user/1/password/
Exception Value: user_change_password() got an unexpected keyword argument 'extra_context'
How can I localize this problem?
What's happening...
I have no idea tbh. It is worth noting a few things though, that the url, should call a method in the User Auth ModelAdmin at django/contrib/auth/admin called user_change_password. It has the following signature:
def user_change_password(self, request, id, form_url=""):
which is why the error is being raised, because somehow extra_context is being passed to it.
There is also a way for you to change the logged on users password, which does accept a extra_context kwarg. My best guess is that one of the apps has overwritten the standard auth ModelAdmin and done it not quite right. Certainly everything works fine with a fresh django 3.0.7 project.
How can I localize this problem?
I would remove all of your additional apps. Hopefully this will fix the problem. If it doesn't then this becomes more interesting. But if it does, I would add them back in one by one until it breaks, and then you'll figure out which additional app is breaking things.
maybe you even can help me cope with it.
There's a few things I can think of that you could do if you just want to change the password. You can change user details via the shell:
python manage.py shell
Then the following will enable you to change a password:
from auth.models import User
user = User.objects.get(id=1) # Or whatever user you want
user.set_password('my_new_password')
user.save()
This should do the trick. Even easier still, there is a management command that does it (but for this you will need to know the current password). You can simply run:
manage.py changepassword *username*
I had this issue (though in Django 2.2). It started after I took the advice from another Stack Overflow post on adding extra_context to every admin page. This seems harmless, but breaks the "change password" form. In the end I deleted the 'extra_context' changes to urls.py and added the extra_context ONLY to the admin forms I needed using the ModelAdmin add_view and change_view methods.
# New Layer Form
def add_view(self, request, form_url='', extra_context={}):
extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
return super(LayerAdmin, self).add_view(request, form_url, extra_context)
# Edit Layer Form
def change_view(self, request, object_id, extra_context={}):
extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
return super(LayerAdmin, self).change_view(request, object_id, extra_context=extra_context)
Here are the commits for full context:
Breaking Commit
urls.py
Fixing Commits
urls.py
admin.py

Django-notification invalid literal for int() with base 10

I'm using django-notification to create notifications. based on it's documention I putted:
url(r'^inbox/notifications/', include(notifications.urls, namespace='notifications')),
in my urls.py. I generate a notification for test by using this in my views.py:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')
and I can easily get the number of unread notification in this url:
http://127.0.0.1:8000/inbox/notifications/api/unread_count/
it return {"unread_count": 1} as I want. but with /api/unread_list/ I can not to get the list of notifications and I get this error:
ValueError at /inbox/notifications/
invalid literal for int() with base 10: '<property object at 0x7fe1b56b6e08>'
As I beginner in using django-notifications any help will be appreciated.
Full TraceBack
Environment:
Request Method: GET Request URL:
http://127.0.0.1:8000/inbox/notifications/api/unread_list/
Django Version: 2.0.2 Python Version: 3.5.2 Installed Applications:
['django.contrib.admin', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.sites', 'django.forms', 'rest_framework',
'allauth', 'allauth.account', 'allauth.socialaccount', 'guardian',
'axes', 'django_otp', 'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp', 'two_factor', 'invitations',
'avatar', 'imagekit', 'import_export', 'djmoney', 'captcha',
'dal', 'dal_select2', 'widget_tweaks', 'braces', 'django_tables2',
'phonenumber_field', 'hitcount', 'el_pagination',
'maintenance_mode', 'notifications', 'mathfilters',
'myproject_web', 'Order', 'PhotoGallery', 'Search', 'Social',
'UserAccount', 'UserAuthentication', 'UserAuthorization',
'UserProfile'] Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_otp.middleware.OTPMiddleware',
'maintenance_mode.middleware.MaintenanceModeMiddleware']
Traceback:
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/exception.py"
in inner
35. response = get_response(request)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
128. response = self.process_exception_by_middleware(e, request)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/notifications/views.py"
in live_unread_notification_list
164. if n.actor:
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/fields.py"
in get
253. rel_obj = ct.get_object_for_this_type(pk=pk_val)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/models.py"
in get_object_for_this_type
169. return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in get
394. clone = self.filter(*args, **kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in filter
836. return self._filter_or_exclude(False, *args, **kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in _filter_or_exclude
854. clone.query.add_q(Q(*args, **kwargs))
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in add_q
1253. clause, _ = self._add_q(q_object, self.used_aliases)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in _add_q
1277. split_subq=split_subq,
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in build_filter
1215. condition = self.build_lookup(lookups, col, value)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in build_lookup
1085. lookup = lookup_class(lhs, rhs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py"
in init
18. self.rhs = self.get_prep_lookup()
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py"
in get_prep_lookup
68. return self.lhs.output_field.get_prep_value(self.rhs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/fields/init.py"
in get_prep_value
947. return int(value)
Exception Type: ValueError at /inbox/notifications/api/unread_list/
Exception Value: invalid literal for int() with base 10: ''
The actor_object_id needs to be a CharField to support UUID based primary keys.
oops! It was my mistake.
I Finally find out what was the problem. actor_object_id was the field of notifications_notification table, which User.objects.get(username = 'SirSaleh') saved in it. It should be Interger (user_id of actor).
So I dropped previous table changed instance to User.objects.get(username = 'SirSaleh') to User ID. Problem solved.
So Why type of actor_object_id is CharField (varchar)? (at least I don't know) ;))
This is old, but I happen to know the answer.
In your code, you wrote:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')
You express that you want guy to be your sender However, in notify.send, you marked the sender as a generic User object, not guy.
So, change your code to:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=guy, recipient=guy, verb='you visted the site!')
Notifications will take the user object guy, extrapolate the ID and store it in the database accordingly.

Django 1.9: 'AnonymousUser' object is not iterable

I was working on a Django 1.9 project, and suddenly this error popped up when I attempted to view my site's home page as a logged-out user.
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.9.7
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'captcha',
'debug_toolbar',
'django_extensions',
'djstripe',
'crm',
'launch',
'rentals',
'widget_tweaks']
Installed Middleware:
[u'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'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']
Traceback:
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/response.py" in rendered_content
137. content = template.render(context, self._request)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/backends/django.py" in render
95. return self.template.render(context)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/base.py" in render
204. with context.bind_template(self):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/debug_toolbar/panels/templates/panel.py" in _request_context_bind_template
79. context = processor(self.request)
File "/Users/me/projects/rentalguru/src/rentals/processors.py" in allCategories
4. expense_categories = ExpenseCategory.objects.filter(user=request.user)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
122. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/query.py" in filter
790. return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/query.py" in _filter_or_exclude
808. clone.query.add_q(Q(*args, **kwargs))
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in add_q
1243. clause, _ = self._add_q(q_object, self.used_aliases)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in _add_q
1269. allow_joins=allow_joins, split_subq=split_subq,
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_filter
1174. self.check_related_objects(field, value, opts)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in check_related_objects
1073. for v in value:
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/utils/functional.py" in inner
205. return func(self._wrapped, *args)
Exception Type: TypeError at /
Exception Value: 'AnonymousUser' object is not iterable
I'm not sure what would be causing this, and there's only one Google search result (for this site) for this error. I searched the code for the is_authenticated() method and didn't find anything, so I'm unsure where to turn. Working through the stack trace didn't show any useful (for me) information.
Here is my view:
class HomePageView(TemplateView):
template_name = 'home.html'
No login decorators or wrapped functions that I can tell.
Let me know if I need to post anything else.
EDIT: Asked for the model, here is the offending context processor instead:
def allCategories(request):
expense_categories = ExpenseCategory.objects.filter(user=request.user)
tags = {'categories': expense_categories}
return tags
I just stumbled myself upon this error. Thankfully the answer was provided in the comments:
As you said you tried to view home page with logged out user and this ExpenseCategory.objects.filter(user=request.user) filtering of Anonymous user (because you are logged out now) seems to be the culprit. Either you should allow only a authenticated user to this view or handle the case where your user is Anonymous
As for myself, I had a view, where I was filtering on a model based on the current user, which apparantly fails, when the user is the AnonymousUser.
I fixed this by adding a check:
if request.user.is_active:
expense_categories = ExpenseCategory.objects.filter(user=request.user)
Note that some people seem to prefer to check request.user.is_authenticated instead.
If you are dealing with a view that shall be accessed by logged in users only, you can also use the #login_required decorator.
For reference:
https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_active
https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_authenticated
https://docs.djangoproject.com/en/1.11/topics/auth/default/#django.contrib.auth.decorators.login_required

Django registration [Errno 10013] error

so for some reason this error([Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions), keeps occurring. when i try to use registration in Django. I am using windows 7 and pycharm IDE with django 1.65. I have already tried different ports to run server (8001 & 8008) and also adding permission in windows firewall and kasperesky firewall for python.exe and pycharm. Any suggestion.
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8001/accounts/register/
Django Version: 1.6.5
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'profiles',
'south',
'registration',
'PIL',
'stripe')
Installed Middleware:
('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')
Traceback:
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\handlers\base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in dispatch
79. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\views\generic\base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in post
35. return self.form_valid(request, form)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in form_valid
82. new_user = self.register(request, **form.cleaned_data)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\backends\default\views.py" in register
80. password, site)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\db\transaction.py" in inner
431. return func(*args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\models.py" in create_inactive_user
91. registration_profile.send_activation_email(site)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\models.py" in send_activation_email
270. self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\contrib\auth\models.py" in email_user
413. send_mail(subject, message, from_email, [self.email])
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\__init__.py" in send_mail
50. connection=connection).send()
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\message.py" in send
274. return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\backends\smtp.py" in send_messages
87. new_conn_created = self.open()
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\backends\smtp.py" in open
48. local_hostname=DNS_NAME.get_fqdn())
File "C:\Python27\Lib\smtplib.py" in __init__
251. (code, msg) = self.connect(host, port)
File "C:\Python27\Lib\smtplib.py" in connect
311. self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\Lib\smtplib.py" in _get_socket
286. return socket.create_connection((host, port), timeout)
File "C:\Python27\Lib\socket.py" in create_connection
571. raise err
Exception Type: error at /accounts/register/
Exception Value: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
The problem has to do with your email server setup. Instead of figuring out what to fix, just set your EMAIL_BACKEND in settings.py to the following:
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
This way, any email sent by django will be shown in the console instead of attempting delivery. You can then continue developing your application.
Having emails printed on the console is good if you are developing, but it can be a headache if your application is sending a lot of emails across.
A better solution is to install mailcatcher. This application will create a local mail server for testing and as a bonus, provide you a web interface where you can view the emails being sent by your server:
It is a Ruby application, and as you are on Windows, I would suggest using rubyinstaller to help with gem installation.
The website also shows you how to configure django:
if DEBUG:
EMAIL_HOST = '127.0.0.1'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 1025
EMAIL_USE_TLS = False
This has nothing to do with your webserver ports, this is to do with the host and port that smtplib is trying to open in order to send an email.
These are controlled by settings.EMAIL_HOST and settings.EMAIL_PORT. There are other settings too, see the documentation for details on how to set up email properly.

Integrity Error May not be null

I am building a website similar to a bartering website, but we are bartering Time,
I have a class Transaction, where it takes the "offer" value, deductions that value from the balance of the requesting user, and credits the value to the Offer'r.
Right now when I click on "Accept Offer" from my template I get this error
ofertoj_transaction.accepted_by may not be NULL
Stacktrace:
IntegrityError at /oferto/accept/
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/oferto/accept/?offer_id=1&creator=2
Django Version: 1.5.4
Python Version: 2.7.4
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.comments',
'django.contrib.sitemaps',
'zinnia',
'tagging',
'mptt',
'south',
'registration',
'blogs',
'turtle',
'ofertoj',
'petoj',
'x',
'profiles')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/home/talisman/projects/tempilo/ofertoj/views.py" in get
74. accepted_by=self.request.user.id
File "/home/talisman/projects/tempilo/ofertoj/models.py" in create
59. new_transaction.save()
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/models/base.py" in save
546. force_update=force_update, update_fields=update_fields)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/models/base.py" in save_base
650. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/models/manager.py" in _insert
215. return insert_query(self.model, objs, fields, **kwargs)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/models/query.py" in insert_query
1675. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/models/sql/compiler.py" in execute_sql
937. cursor.execute(sql, params)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/backends/util.py" in execute
41. return self.cursor.execute(sql, params)
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/backends/sqlite3/base.py" in execute
364. six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/home/talisman/virt_env/tempilo/local/lib/python2.7/site-packages/Django-1.5.4-py2.7.egg/django/db/backends/sqlite3/base.py" in execute
362. return Database.Cursor.execute(self, query, params)
Exception Type: IntegrityError at /oferto/accept/
Exception Value: ofertoj_transaction.accepted_by may not be NULL
part of ofertoj.views.py
class TransactionView(TemplateView, LoginRequiredMixin):
template_name = "ofertoj/offer_accepted.html"
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
if self.request.GET.get("offer_id"):
oferto = Oferto.objects.get(id=self.request.GET.get("offer_id"))
if oferto.valid:
transaction = Transaction()
transaction.create(
creator=self.request.GET.get("creator"),
amount=oferto.time,
accepted_by=self.request.user.id
)
acceptor = Profile.objects.get(user=self.request.user)
acceptor.balance = acceptor.balance - oferto.time
acceptor.save()
# credit the coins to the creator
creator = Profile.objects.get(user=oferto.user)
creator.balance = creator.balance + oferto.time
creator.save()
else:
return HttpResponse("This offer is already accepted")
else:
raise Http404
return self.render_to_response(context)
Part of Ofertoj.models
class Transaction(models.Model):
creator = models.IntegerField()
amount = models.IntegerField()
accepted_by = models.IntegerField()
def __unicode__(self):
return self.id
def create(self, **kwargs):
new_transaction = Transaction(
creator = kwargs['creator'],
amount = kwargs['amount'],
accepted_by = kwargs['accepted_by']
)
new_transaction.save()
return
this line is highlited in the stacktrace
acceptor = Profile.objects.get(user=self.request.user)
ofertoj.urls
url(
regex=r"^accept/$",
view = TransactionView.as_view(),
name = "accept_offer"
),
part of my template
{% if oferto.valid and not oferto.user == request.user %}
Accept this Offer
{% endif %}
<br /><br />
Your ofertoj application is trying to store a Transaction object which has an accepted_by field which is NULL but your database schema does not allow this field to be NULL.
Check this code:
transaction.create(
creator=self.request.GET.get("creator"),
amount=oferto.time,
accepted_by=self.request.user.id
)
and the code of transaction.create.
One possibility: if your user is not logged in then self.request.user.id will be None, and this translates to NULL in the database. I do not see anything in your code that requires the user to be logged in.
it was an issue with unicode method in the Profile model
and since, the balance was default null