Forums

Authentication error. Django.

Hi, everyone!

On my local machine evrething is fine, but when i trying to deploy my code to pythonanywhere, i got such problem during user registration.

Any ideas how to fix it?

Problem

> Environment:

Request Method: POST
Request URL: http://scorpionby.pythonanywhere.com/adminauth/user/add/

Django Version: 1.8
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',
 'article',
 'loginsys')
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 "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/admin/options.py" in wrapper
  616.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/admin/sites.py" in inner
  233.             return view(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in inner
  145.                     return func(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/admin.py" in add_view
  121.                                                extra_context)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/admin/options.py" in add_view
  1516.         return self.changeform_view(request, None, form_url, extra_context)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/utils/decorators.py" in inner
  145.                     return func(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/admin/options.py" in changeform_view
  1467.                 self.save_model(request, new_object, form, not add)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/admin/options.py" in save_model
  1078.         obj.save()
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py" in save
  710.                        force_update=force_update, update_fields=update_fields)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py" in save_base
  738.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py" in _save_table
  822.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py" in _do_insert
  861.                                using=using, raw=raw)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/manager.py" in manager_method
  127.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/query.py" in _insert
  920.         return query.get_compiler(using=using).execute_sql(return_id)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/sql/compiler.py" in execute_sql
  963.                 cursor.execute(sql, params)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/home/scorpionby/.virtualenvs/djangoenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/sqlite3/base.py" in execute
  318.         return Database.Cursor.execute(self, query, params)

Exception Type: IntegrityError at /adminauth/user/add/
Exception Value: NOT NULL constraint failed: auth_user.last_login

[ edited by admin: formatting ]

what does loginsys do?

It is responsible for log in, log out, and register new users. Almost all of the code I got from here

does the exact same code as the github repo run? or does it error as well?

app loginsys is exactly the same.. the problem is that on my localhost - evrything is ok, but on your doesn't.

just took a look at your log files and want to clarify how a virtualenv works:

A virtualenv is specific to a webapp on a particular machine and contains the libraries and packages your app depends on. For example, you might create a virtualenv for your webapp on your local machine and install a particular version of flask, django, or requests, etc into it, or you might then create a second virtualenv on your local machine for another project that you are working on, or you might create a third virtualenv on pythonanywhere for your webapp.

The actual source code for your website -- the python and html files you write yourself, that are part of your site -- this is what you would move between machines, but they don't need to and should not be placed in the same folder as your virtualenv.

So if you look at your error log, and go to the very bottom (since it is chronological), you will see that you are having trouble with the file paths. (It can't find settings.py)

I think it's an old log... and he is not to treat the problem

Which database are you using? Could it be that the database is slightly different on your local PC and on PythonAnywhere?

Also, just to double-check -- are you definitely using the same versions of django, etc, locally and on pythonanywhere?

Conrad is right about not mixing virtualenvs and application source code by the way. You should keep your app code at, eg, /home/scorpionby/mysite/, or somewhere like that. You should be able to delete and re-create your virtualenv at any time, totally separately from your code. (that may be worth trying).

The other piece of advice, if you're having database problems, would be to reset your database completely -- delete it, or start again with a new one, and run manage.py migrate...