Detecting and correcting Circular Imports - python

So, this is an extension of what I asked last week (Why do I need to import a class within this class, instead of at the top of the file?) but after extensive debugging, I feel like it might warrant a new question.
I have a number of modules, all with imports. I suspect there may be a circular import but I haven't been able to find it.
Here's the weird thing:
In one models.py file, I have:
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from heythere.models import Notification as HeyThere
from heythere.models import NotificationManager as HeyThereManager
from django.contrib.auth.models import User
then some model definitions, including one with a method:
def to_user(self):
try:
return User.objects.get(username=str(self.username))
except ObjectDoesNotExist:
return None
and a little further down:
from ownership.apps.Assets.models import Item
When it's like this, I get AttributeError: 'NoneType' object has no attribute 'objects' (referring to User). So it's set to None, somehow, as opposed to raising a global name XXX is not defined.
BUT THEN, I tried accessing the User right after the import:
me = User.objects.get(username='xxxx')
print me
It printed correctly upon running runserver, so I know it can access User there, but then gave me the error message ImportError: cannot import name Item. How did simply accessing the model cause an import error? (FWIW, Item does have a number of FK relations to User)
What gives?
Traceback when User.objects.get() is included:
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
self.validate(display_num_errors=True)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/models.py", line 12, in <module>
import permissions
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/permissions.py", line 4, in <module>
from ownership.apps.Shared.models import Person
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py", line 87, in <module>
from ownership.apps.Assets.models import Item
ImportError: cannot import name Item
And without (how the code should work):
Environment:
Request Method: POST
Request URL: http://localhost:8000/application/new
Django Version: 1.6.1
Python Version: 2.7.2
Installed Applications:
('suit',
'south',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.redirects',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'rest_framework',
'ldap_sync',
'crispy_forms',
'ownership.apps.Catalog',
'ownership.apps.Assets',
'ownership.apps.Shared',
'ownership.libs.display',
'django_tables2',
'haystack',
'autocomplete_light',
'reversion',
'heythere',
'polymorphic',
'django_extensions',
'debug_toolbar')
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.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
'ownership.libs.shibboleth.CustomHeaderMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/crud_views.py" in connect_create_view
48. return subview.as_view()(request, model_name=model_name)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Users/xxxxx/.virtualenvs/ownership/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/crud_views.py" in post
280. create_new_asset_notification(request, new_item)
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/views.py" in create_new_asset_notification
123. send_email(request, subject, body, owner.to_user().email, )
File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py" in to_user
52. return User.objects.get(username=str(self.username))
Exception Type: AttributeError at /application/new
Exception Value: 'NoneType' object has no attribute 'objects'

Note this in my stack trace:
File "/Users/xxxxx/code/ownership/ownership/apps/Assets/models.py", line 12, in <module>
import permissions File "/Users/xxxxx/code/ownership/ownership/apps/Assets/permissions.py", line 4, in <module>
from ownership.apps.Shared.models import Person File "/Users/xxxxx/code/ownership/ownership/apps/Shared/models.py", line 87, in <module>
from ownership.apps.Assets.models import Item
Assets/models.py was importing permissions
Permissions was importing Shared.models.Person
Shared/models was importing Assets.models.Item
which was a circular import.
This was corrected by moving from django.contrib.auth.models import User to inside of the Person model. I don't quite understand why--if anyone wants to elaborate and provide a better explanation before I accept my own answer, please do.

Related

hello I am new I am lost with this problem object has no attribute 'get ,someone who can guide me?

I'm looking for a solution to this error in Django. I sent you my forms and my view, and the error is as follows in my app . According to what appears to me in the tracer back, I would mark an error in the views line if form.is_valid() I already looked at a lot of things, but the truth is I'm already lost. I need help with the damn error.
The CargaForm object has no attribute 'get
Traceback
Request Method: POST
Request URL: http://127.0.0.1:8000/tienda/cargar/
Django Version: 3.2.13
Python Version: 3.10.6
Installed Applications:
['django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'captcha',
'productos.apps.ProductosConfig',
'web.apps.WebConfig',
'contacto.apps.ContactoConfig',
'tienda.apps.TiendaConfig',
'debug_toolbar']
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',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Traceback (most recent call last):
File "C:\Users\PY310\diplo\lib\site-packages\django\core\handlers\exception.py", line 47,
in inner
response = get_response(request)
File "C:\Users\PY310\diplo\lib\site-packages\django\core\handlers\base.py", line 181, in
_get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\PY310\diplo\Proyectos\cerverzeria\cerverzeria\tienda\views.py", line 13, in
cargar_imagen
if form.is_valid():
File "C:\Users\PY310\diplo\lib\site-packages\django\forms\forms.py", line 175, in is_valid
return self.is_bound and not self.errors
File "C:\Users\PY310\diplo\lib\site-packages\django\forms\forms.py", line 170, in errors
self.full_clean()
File "C:\Users\PY310\diplo\lib\site-packages\django\forms\forms.py", line 372, in full_clean
self._clean_fields()
File "C:\Users\PY310\diplo\lib\site-packages\django\forms\forms.py", line 384, in
_clean_fields
value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
File "C:\Users\PY310\diplo\lib\site-packages\django\forms\widgets.py", line 263, in
value_from_datadict
return data.get(name)
Exception Type: AttributeError at /tienda/cargar/
Exception Value: 'CargaForm' object has no attribute 'get'
Forms------------------------------
from django.forms import ModelForm
from productos.models import Producto
class CargaForm(ModelForm):
class Meta:
model= Producto
fields = ['Producto', 'Marca', 'fecha_publicacion', 'imagen']
def __init__(self, *args, **Kwargs):
super(CargaForm, self).__init__(self, *args, **Kwargs)
Views--------------------------------
from django.shortcuts import render
from django.shortcuts import redirect
from tienda.forms import CargaForm
from productos.models import Producto
def cargar_imagen(request):
params={}
if request.method =='POST':
form = CargaForm(request.POST, request.FILES)
params['form'] = form
if form.is_valid():
producto = form.cleaned_data['producto']
fecha_publicacion = form.cleaned_data['fecha_publicacion']
imagen = form.cleaned_data['imagen']
nuevo_producto = Producto(producto=producto, fecha_publicacion=fecha_publicacion, imagen=imagen)
nuevo_producto.save()
return redirect('index')
else:
form= CargaForm()
params['form'] = form
return render(request, 'tienda/formulario.html', params)
your mistake is in the file 'widgets.py',and i suggest you should change like this.
change
return data.get(name)
into:
return data.POST.get(name)

Django TinyMCE: 'ModelFormMetaclass' object is not iterable

I'm currently working with the Django framework to build a content management system into a company website, and after successfully completing one page, began work on a different page that requires a rich text editor within the admin interface.
Having chosen TinyMCE for the job, I spent a lot of time on Monday trying to get it running correctly, but only managed to include a simple HTMLField(). Having been slightly confused by a number of differing tutorials, I've now encountered an error that I'm struggling to find a solution to, and one which I hoped the StackOverflow community might be able to help with.
Currently, I have the following code:
admin.py
from django.forms import *
from django.db.models import *
from tinymce.widgets import TinyMCE
from models import *
from django.contrib import admin
#class MyModelForm(forms.ModelForm):
#content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#class Meta:
#model = MyModel
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
admin.site.register(MyModelForm, MyModelAdmin)
The majority of this code has been commented out for debugging purposes, as the problem seems to be with models.py:
models.py
from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE
class MyModelForm(forms.ModelForm):
content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows' : 30}))
class Meta:
model = FlatPage
This is the traceback I'm being presented with:
Environment:
Request Method: GET
Request URL: mycomputer.mydomain/company/admin/
Django Version: 1.5.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',
'django.contrib.admin',
'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'cms.plugins.file',
'cms.plugins.link',
'cms.plugins.picture',
'cms.plugins.text',
'reversion',
'grappelli',
'profiles',
'tinymce',
'testapp',
'django_reset')
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',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/companycms/urls.py" in <module>
7. admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/systems/vhost-trunk/djangocms/companycms/testapp/admin.py" in <module>
17. admin.site.register(MyModelForm, MyModelAdmin)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in register
77. for model in model_or_iterable:
Exception Type: TypeError at /admin/
Exception Value: 'ModelFormMetaclass' object is not iterable
As you can see, tinymce appears to be correctly installed, and the problem lies with models.ModelForm
My aim, in case it isn't clear, is to create a simple MyModel model with one content field, editable using the TinyMCE Editor. If you think I could supply any more code to shed more light on the situation, please let me know. Thanks.
I think I'm a bit confused with your model definition, either way I think your error is in this line
admin.site.register(MyModelForm, MyModelAdmin)
unless I'm being fooled by the name MyModelForm you are passing a ModelForm to the register method which takes a models.Model subclass as an argument.
This is really late to the party but this is what you need.
admin.site.register(MyModel, MyModelAdmin)
The MyModelAdmin has the MyModelForm and admin.site.register takes a Model and a ModelAdmin

ImproperlyConfigured at / 'ClientEventLogAdmin.exclude' refers to field 'created' that is missing from the form

I am installing a django application module.I am getting this error.
I started another MicroInstance and reinstalled everything but still I am getting this error.
.
Environment:
Request Method: GET
Request URL: http://54.235.127.252/mds/
Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['sana.mrs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'sana.mrs.util.LoggingMiddleware')
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/opt/sana/urls.py" in <module>
12. admin.autodiscover()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
26. import_module('%s.admin' % app)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/opt/sana/mrs/admin.py" in <module>
26. admin.site.register(ClientEventLog, ClientEventLogAdmin)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in register
97. validate(admin_class, model)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in validate
24. validate_base(cls, model)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in validate_base
279. check_formfield(cls, model, opts, 'exclude', field)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/validation.py" in check_formfield
369. "is missing from the form." % (cls.__name__, label, field))
Exception Type: ImproperlyConfigured at /
Exception Value: 'ClientEventLogAdmin.exclude' refers to field 'created' that is missing from the form.
Note:I just need to install this application.I am intermediate in python.and beginner in Django.But professional in PHP,mysql and front end with jQuery
From what I see, the problem is likely to be related to the moca framework.
If your /opt/sana/mrs/admin.py file looks like this then the culprit is likely to be located at line 12 : the created field is refered in the exclude list, but not previously defined.
As I'm not sure about your needs here are some solutions you can try :
Re-install or update your moca frameword ;
Add a piece of code before the execute definition (not sure what's type it should be though) :
from django.db import models # You may also place it in the top of the file
created = models.DateField(blank=True, null=True)
Remove the created item from the exclude list (not sure about the impact though)
Hope it helps,

Using reverse() in django forms

I'm trying to use django's reverse() function in definition of django form for my custom widget, but am getting an error:
ImproperlyConfigured
The included urlconf urls doesn't have any patterns in it
Here is the code:
class WorkForm(forms.Form):
# ...
category = forms.ChoiceField(
required=True,
label=_('Category'),
help_text=_('Select most appropriate category for your work.')
)
subcategory = forms.ChoiceField(
widget=DependantChoiceWidget(
default_value=_('Select category first'),
data_source_url=reverse('works-json-categories'),
# data_source_url='', -- it works this way
depends_on='category_id'
),
required=True,
label=_('SubCategory'),
help_text=_('Which subcategory suits your work best.')
)
I am pretty sure, that my 'works.urls' is configured properly, since all other pages work as expected.
Is there a reason, why I cannot use reverse() in form definition? Does it have something to do with when this code runs? Is there a way to fix this, or the only choice here is to hardcode the URL?
Here is full error dump:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/works/add?category=1&subcategory=1
Django Version: 1.4 pre-alpha
Python Version: 2.7.1
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',
'social_auth',
'sorl.thumbnail',
'helpers',
'users',
'works',
'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
67. if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in _is_valid_path
164. urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
416. return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/megenius/trunk/urls.py" in <module>
27. url(r'^works/', include('works.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
24. urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/megenius/trunk/works/urls.py" in <module>
2. from works.views import *
File "/var/www/megenius/trunk/works/views.py" in <module>
9. from works.forms import WorkForm
File "/var/www/megenius/trunk/works/forms.py" in <module>
10. class WorkForm(forms.Form):
File "/var/www/megenius/trunk/works/forms.py" in WorkForm
31. data_source_url=reverse('works-json-categories'),
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
473. (prefix, resolver.reverse(view, *args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
360. possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
276. self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
242. for pattern in reversed(self.url_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
332. raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
Exception Type: ImproperlyConfigured at /works/add
Exception Value: The included urlconf urls doesn't have any patterns in it
The problem might be that the form is defined before the urls have been loaded.
Django 1.4 will have a reverse_lazy feature that would solve this problem. You could implement it in your project yourself (see changeset 16121).
Alternatively, you could set the widget in your forms __init__ method instead. Then the reverse call happens when the form is created, after the urls have loaded.
class WorkForm(forms.Form):
# ...
subcategory = forms.ChoiceField(
required=True,
label=_('SubCategory'),
help_text=_('Which subcategory suits your work best.')
)
def __init__(self, *args, **kwargs):
super(WorkForm, self).__init__(*args, **kwargs)
self.fields['subcategory'].widget=DependantChoiceWidget(
default_value=_('Select category first'),
data_source_url=reverse('works-json-categories'),
depends_on='category_id'
),

'WSGIRequest' object has no attribute 'user' in Google App Engine

I'm new to django and Google App Engine, and I'm having trouble with using the datastore. Every time I make a query, such as
db.GqlQuery("SELECT * FROM Listing ORDER BY date DESC LIMIT 10")
I receive the error:
'WSGIRequest' object has no attribute 'user'
This error seems to be generated in context_processors.py within the django core. Now, the advice I've found on the Internet said to comment out user-related INSTALLED_APPS and MIDDLEWARE_CLASSES, but this does not seem to help. My code looks like this:
MIDDLEWARE_CLASSES = (
# 'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.middleware.doc.XViewMiddleware',
)
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
)
My Listing object is defined as the following (it had a author property earlier, but this is now commented out and the object was redefined with a new name):
class Listing(db.Model):
#author = db.UserProperty()
address = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
coords = db.GeoPtProperty()
Does anyone know what is causing this error, and how to fix it? Is it perhaps a case of having to reset the settings somehow?
UPDATE
The solution suggested by sdolan seems to be to add the following to the settings.py of the app:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.debug",
"django.core.context_processors.i18n")
This effectively removes the third default processor, django.core.context_processors.auth (which shouldn't be there because for AppEngine we don't want Django's auth component).
Thank you, sdolan, for the solution! hopefully someone else can use it, too. :)
#Nick, I think it's worth putting this golden piece about CONTEXT_PROCESSORS in the tutorial (http://code.google.com/appengine/articles/django.html)
(Original followup to the question)
Have the same problem, looking for solution.... All works fine when settings.py contains
DEBUG = True
but this error pops up (and kills my motivation to proceed with learning) when I switch to
DEBUG = False
#Nick Johnson, here's the stack trace:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3211, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3154, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 527, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2404, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2314, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2212, in ExecuteOrImportScript
script_module.main()
File "C:\Dev\appengine\djangotest\main.py", line 37, in main
util.run_wsgi_app(application)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 97, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 115, in run_bare_wsgi_app
result = application(env, _start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\wsgi.py", line 189, in __call__
response = self.get_response(request)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\base.py", line 103, in get_response
return callback(request, **param_dict)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\views\defaults.py", line 79, in page_not_found
return http.HttpResponseNotFound(t.render(RequestContext(request, {'request_path': request.path})))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\context.py", line 100, in __init__
self.update(processor(request))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\context_processors.py", line 18, in auth
'user': request.user,
AttributeError: 'WSGIRequest' object has no attribute 'user'

Categories

Resources