<Model> matching query does not exist - django

I've learned python django since three days ago .
I wanted to remove an field from model, so I put the '#' front of that field.
Then I started the server again, but it gave me such an error message
'Userprofile matching query does not exist' (Userprofile is the model which I made.)
How can I solve this problem. I'm just a totally new to django, so even it's not easy to question my problem. If the clue is not enough, please tell me what other information is need.
p.s here is the total error message.
Environment:
Request Method: GET
Request URL: h ttp://localhost:8000/
Django Version: 1.6.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'south',
'autocomplete_light',
'djcelery',
'asap_web',
'facebook',
'venue',
'notification',
'study',
'general',
'member',
'advertise')
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')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in __call__
89. return main()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in main
25. return process_request()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in process_request
53. return _call_proper_request_processor()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in _call_proper_request_processor
77. return getattr(self, method_name)(request, *self.args, **kwargs)
File "/home/jaehoon/PycharmProjects/studysearch/general/views.py" in process_get_request
19. if user.is_authenticated() and user.get_profile().is_required_more_info:
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in get_profile
441. self._state.db).get(user__id__exact=self.id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in get
307. self.model._meta.object_name)
Exception Type: DoesNotExist at /
Exception Value: UserProfile matching query does not exist.

The exception is DoesNotExist which is thrown when you use get to retrieve single instance but it does not exist. In your process_get_request view:
user.get_profile().is_required_more_info
is throwing this exception because there is no profile created for this user. Note that user.get_profile() is deprecated since django 1.5 and you should use OneToOne field or custom user model instead, from docs:
get_profile() Deprecated in Django 1.5: Deprecated since version 1.5:
With the introduction of custom User models, the use of
AUTH_PROFILE_MODULE to define a single profile model is no longer
supported. See the Django 1.5 release notes for more information.

Related

Django registration error after switching interpreter to Python 2.78

I initially had python 3.4 installed with django 1.65. But i searched and found out Django registration doesn't work with python 3. So I downloaded python 2.78 and even uninstalled python 3.4.
However When i am on url http://www.localhost:8000/accounts/register/ and try to register a user an error comes up. It seems like its django registration is still reading my old virtual env linked to python 3.4 and its path. I have edited my environmental variable PATH to delete any Python 3.4 and replaced with Python 2.7. But still same error occurs. I'm new to web development. Sorry if I didn't provide enough detail or to little detail.
TypeError at /accounts/register/
Unicode-objects must be encoded before hashing
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.6.5
Exception Type: TypeError
Exception Value:
Unicode-objects must be encoded before hashing
Exception Location: C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py in create_profile, line 106
Python Executable: C:\Users\jasan\virtual_enc_matchmaker\Scripts\pythonw.exe
Python Version: 3.4.1
Python Path:
['C:\\Users\\jasan\\PycharmProjects\\matchmaker',
'C:\\Users\\jasan\\PycharmProjects\\matchmaker',
'C:\\WINDOWS\\SYSTEM32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34',
'C:\\Users\\jasan\\virtual_enc_matchmaker',
'C:\\Users\\jasan\\virtual_enc_matchmaker\\lib\\site-packages']
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.6.5
Python Version: 3.4.1
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_enc_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_enc_matchmaker\lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in dispatch
79. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\views\generic\base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in post
35. return self.form_valid(request, form)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in form_valid
82. new_user = self.register(request, **form.cleaned_data)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\backends\default\views.py" in register
80. password, site)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\db\transaction.py" in inner
431. return func(*args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py" in create_inactive_user
88. registration_profile = self.create_profile(new_user)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py" in create_profile
106. salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
Exception Type: TypeError at /accounts/register/
Exception Value: Unicode-objects must be encoded before hashing

Django Type Error - render to string got multiple values for keyword argument context_instance

I'm new in django and I collect all the static and templates from the admin site to customize. Now I'm trying to render a queryset to the change_list.html from the admin site.
view.py
def person_list(request):
if request.method == 'GET':
qs = Person.objects.all()
return render(request, 'admin/change_list.html', {'app_label': 'clients'}, {'results_list':qs})
else:
return render(request, 'admin/change_list.html')
And I'm getting this type error:
render_to_string() got multiple values for keyword argument 'context_instance'
Here is the full traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/clients/persons/
Django Version: 1.5.1
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',
'equipment',
'workers',
'clients',
'rents',
'bills',
'pays')
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')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/home/facundo/dev/BLPServicios/blpservicios/clients/views.py" in persona_list
9. return render(request, 'admin/change_list.html', {'app_label': 'clients'}, {'results_list':qs})
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" in render
53. return HttpResponse(loader.render_to_string(*args, **kwargs),
Exception Type: TypeError at /clients/persons/
Exception Value: render_to_string() got multiple values for keyword argument 'context_instance'
Can you help me solve this? Thanks!
Try send values in one dictionary
{'app_label': 'clients', 'results_list':qs}
i think you are using the admin module to do something it can't... what are you trying to do?
i guess you'd better try to do it without the admin. often customizing it is more painful than implementing the code yourself, because of its complexity!
in particular, the {% result_list cl %} tag you see in the admin tamplate change_list.html (line 91) is not a template varible (that you are trying to pass in the context) but a template custom tag! whatever you want to do, this is the wrong path ;)

Site matching query does not exist. Lookup parameters were {'pk': 3}

Environment:
Request Method: GET
Django Version: 1.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.linkedin',
'django.contrib.admin',
'django.contrib.admindocs')
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')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/var/www/sampleapp/allauth/account/views.py" in dispatch
41. **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py" in get
155. return self.render_to_response(self.get_context_data(form=form))
File "/var/www/sampleapp/allauth/account/views.py" in get_context_data
67. "site": Site.objects.get_current(),
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py" in get_current
26. current_site = self.get(pk=sid)
File "/usr/local/lib/python2.7/dist-packages/django/d
b/models/manager.py" in get
143. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in get
401. (self.model._meta.object_name, kwargs))
Exception Type: DoesNotExist at /accounts/login/
Exception Value: Site matching query does not exist. Lookup parameters were {'pk': 3}
I am new to django,
Help me to fix this issue?
I encountered this problem as well. I was going through the PyCharm Django guide. I fixed this by deleting my sqlite database file and running syncdb again. I don't know why it didn't work the first time, but it works now.
Also, it's probably worth downloading the SQLite Database Browser so that you can see the actual structure of your SQLite database. For this issue, you're interested in the django_site table. After I deleted my database file and reran syncdb, there was one row in this table.
This problem occurs because the first time that you executes python manage.py syncdb. isn't specified a main user. To solve it, delete all tables created by django in data base (with mysql, postgresql..) or delete the database.db (with sqlite3), Then run python manage.py syncdb one more time

django: why do i cannot store twitter.Twitter object into session

I created a twitter.Twitter object, but cannot store it into session. Following is my code.
t = twitter.Twitter(auth=twitter.OAuth(consumer_key, consumer_secret,
oauth_token, oauth_secret))
request.session['t'] = t
but if I store a string like
request.session['t'] = 't'
it works, why? because the twitter#Twitter object is not a serializable object? How can I avoid authenticating each time when I need a twitter#Twitter object? Following is the django trace.
Django Version: 1.3.1
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'myproj.myapp']
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')
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
178. response = middleware_method(request, response)
File "/usr/lib/python2.6/site-packages/django/contrib/sessions/middleware.py" in process_response
36. request.session.save()
File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/file.py" in save
121. os.write(output_file_fd, self.encode(session_data))
File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py" in encode
93. pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
File "/usr/lib/python2.6/site-packages/twitter-1.9.0-py2.6.egg/twitter/api.py" in __call__
173. return self._handle_response(req, uri, arg_data)
File "/usr/lib/python2.6/site-packages/twitter-1.9.0-py2.6.egg/twitter/api.py" in _handle_response
198. raise TwitterHTTPError(e, uri, self.format, arg_data)
Exception Type: TwitterHTTPError at /tool/log_in/
Exception Value:
Exactly as you guessed, you can only store pickleable objects.
From the docs
The session dictionary should accept any pickleable Python object. See the pickle module for more information.

Just upgraded to Django 1.4 and getting error with messages

I just upgraded to Django 1.4 and it has broken a couple things including messaging.
Here's the error I get when trying to change a avatar:
'User' object has no attribute 'message_set'
Exception Location: /Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185
Traceback:
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
20. return view_func(request, *args, **kwargs)
File "/Users/nb/Desktop/spicestore/apps/avatar/views.py" in change
76. request.user.message_set.create(
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/functional.py" in inner
185. return func(self._wrapped, *args)
Exception Type: AttributeError at /avatar/change/
Exception Value: 'User' object has no attribute 'message_set'
Also, messaging no longer works on the site. What are the changes in Django 1.4 that could be causing this and has anyone overcome a similar issue?
Django introduced a messages app in 1.2 (release notes), and deprecated the old user messages API.
In Django 1.4, the old message_set API has been removed completely, so you'll have to update your code. If you follow the messages docs, you should find it pretty straight forward.
Add
from django.contrib import messages
And then
def foo(request):
messages.add_message(request, messages.INFO, "Your message.")
What is in your INSTALLED_APPS in your settings.py?
Do you have 'django.contrib.messages', included there?
Something like:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
...
From Django 1.4 docs
To enable message functionality, in settings.py do the following:
Edit the MIDDLEWARE_CLASSES setting and make sure it contains
'django.contrib.messages.middleware.MessageMiddleware'
If you are using a storage backend that relies on sessions (the default), django.contrib.sessions.middleware.SessionMiddleware must be enabled and appear before MessageMiddleware in your MIDDLEWARE_CLASSES.
Edit the TEMPLATE_CONTEXT_PROCESSORS setting and make sure it contains
'django.contrib.messages.context_processors.messages'
Add 'django.contrib.messages' to your INSTALLED_APPS setting
As far as django-avatar is concerned. Use the master files found here: https://github.com/chadpaulson/django-avatar/tree/master/avatar