When setting a simple handler403 for Django:
from django.conf.urls import url
from django.core.exceptions import PermissionDenied
from django.views.generic import TemplateView
class PermissionDeniedView(TemplateView):
template_name = '403.html'
handler403 = PermissionDeniedView.as_view()
def my_view(request):
raise PermissionDenied
urlpatterns = [
url(r'^$', my_view),
]
The browser does not receive any data (ERR_EMPTY_RESPONSE in chrome), and some errors appear on the log:
Traceback (most recent call last):
File "/usr/lib64/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
File "/usr/lib64/python2.7/wsgiref/handlers.py", line 127, in finish_response
for data in self.result:
File "/home/foo/.virtualenvs/bar/lib/python2.7/site-packages/django/template/response.py", line 171, in __iter__
raise ContentNotRenderedError('The response content must be '
ContentNotRenderedError: The response content must be rendered before it can be iterated over.
[20/May/2015 07:26:25]"GET / HTTP/1.1" 500 59
Traceback (most recent call last):
File "/usr/lib64/python2.7/SocketServer.py", line 599, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/foo/.virtualenvs/bar/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 102, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/usr/lib64/python2.7/SocketServer.py", line 655, in __init__
self.handle()
File "/home/foo/.virtualenvs/bar/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 182, in handle
handler.run(self.server.get_app())
File "/usr/lib64/python2.7/wsgiref/handlers.py", line 92, in run
self.close()
File "/usr/lib64/python2.7/wsgiref/simple_server.py", line 33, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
TemplateView returns a TemplateResponse instance with lazy content rendering by default, and is not suitable as is for handler403.
To force this view to render it's content, make sure .render() is called before returning the response:
class PermissionDeniedView(TemplateView):
template_name = '403.html'
def dispatch(self, request, *args, **kwargs):
response = super(PermissionDeniedView, self).dispatch(request, *args, **kwargs)
response.render()
return response
Related
What I am trying to achieve is to customize the oscarapi to expose the partner api to be public api instead of just for admin
I have followed the docs on how to customize the api and also did as suggested by Jamie Marshall in
Extending django-oscarapi API ROOT to custom API class
So far I am able to overwrite the root.py file but failing to get oscar see the new urls.py file.
My work so far is as follows
I created a api_customization/views/partner.py file
I created a api_customization/views/root.py file
I tried to extend the urls.py file by creating a api_customization/urls.py file
However, I'm getting the following error
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.7/contextlib.py", line 74, in inner return func(*args, **kwds)
File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/decorators.py", line 50, in handler return func(*args, **kwargs)
File "/code/.../forked_apps/api_customization/views/root.py", line 52, in api_root apis = PUBLIC_APIS(request, format)
File "/code/.../forked_apps/api_customization/views/root.py", line 29, in PUBLIC_APIS ("partners", reverse("partner-list", request=r, format=f)),
File "/usr/local/lib/python3.7/site-packages/rest_framework/reverse.py", line 47, in reverse url = _reverse(viewname, args, kwargs, request, format, **extra)
File "/usr/local/lib/python3.7/site-packages/rest_framework/reverse.py", line 60, in _reverse url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)
File "/usr/local/lib/python3.7/site-packages/django/urls/base.py", line 87, in reverse return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 685, in _reverse_with_prefix raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'partner-list' not found. 'partner-list' is not a valid view function or pattern name.
[09/Jul/2021 21:18:13] "GET /api/ HTTP/1.1" 500 136185
views/partner.py
from oscarapi.utils.loading import get_api_class
from oscar.core.loading import get_model
from rest_framework import generics
PartnerSerializer = get_api_class("serializers.product", "PartnerSerializer")
Partner = get_model("partner", "Partner")
class PublicPartnerList(generics.ListCreateAPIView):
queryset = Partner.objects.all()
serializer_class = PartnerSerializer
urls.py
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from oscarapi.utils.loading import get_api_class
from oscarapi import urls
PublicPartnerList = get_api_class("views.partner", "PublicPartnerList")
urls.urlpatterns += [
path("partners1/", PublicPartnerList.as_view(), name="partner-list"),
]
urls.urlpatterns += format_suffix_patterns(urls.urlpatterns)
views/root.py
import collections
from django.conf import settings
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
__all__ = ("api_root",)
def PUBLIC_APIS(r, f):
return [
# other urls .......
("partners", reverse("partner-list", request=r, format=f)),
]
# remaining file content ......
I need a direction or a hint on how to achieve this
Any help is appreciated
I found a solution to this and might be helpful form someone
I had to do the same steps done for root.py file to get my app recognise the custom urls.py file
So what I did
copy the content of urls.py
modify the file to suit my needs
update my app urls.py file to point to the custom urls.py file of the api
//So from this
path("api/", include("oscarapi.urls")),
//To this
path("api/", include("APP_NAME.forked_apps.api_customization.urls")),
I tried peewee with flask for two days, but I failed till now. The code is as the follows:
import click
from flask import Flask
from flask.cli import FlaskGroup
from playhouse.flask_utils import FlaskDB
from models import *
from config import config
flask_db = FlaskDB()
def create_app(config_name):
application = Flask(__name__)
application.config.from_object(config[config_name])
flask_db.init_app(application)
flask_db.connect_db()
flask_db.database.create_tables([User])
flask_db.database.close()
#application.route('/')
def index():
return "hello world!"
return application
def create_cli_app(info):
return create_app("develop")
#click.group(cls=FlaskGroup, create_app=create_cli_app)
def cli():
pass
#cli.command()
def initdb():
flask_db.connect_db()
flask_db.database.create_tables([User])
flask_db.database.close()
if __name__ == "__main__":
cli()
When I run it with the CLI: python manage.py run, I got the following errors:
(venv) ➜ /Users/yw/Documents/web git:(master) ✗ p manage.py run
Traceback (most recent call last): File "manage.py", line 46, in
cli() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 716, in call
return self.main(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 345, in main
return AppGroup.main(self, *args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 696, in main
rv = self.invoke(ctx) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 889, in invoke
return ctx.invoke(self.callback, **ctx.params) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 534, in invoke
return callback(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/decorators.py",
line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/click/core.py",
line 534, in invoke
return callback(*args, **kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 388, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) File
"/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 124, in init
self._load_unlocked() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 148, in _load_unlocked
self._app = rv = self.loader() File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/flask/cli.py",
line 201, in load_app
rv = self.create_app(self) File "manage.py", line 30, in create_cli_app
return create_app("develop") File "manage.py", line 19, in create_app
flask_db.database.create_tables([User]) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 3765, in create_tables
create_model_tables(models, fail_silently=safe) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 5175, in create_model_tables
m.create_table(**create_table_kwargs) File "/Users/yw/Documents/web/venv/lib/python3.4/site-packages/peewee.py",
line 4845, in create_table
if db.sequences and pk is not False and pk.sequence: AttributeError: 'FlaskDB' object has no attribute 'sequences'
Indeed, I just want to initiate the DB by using flask.cli tool. As you see, if I use the command “python manage.py initdb”, I can only get the same error output as above.
So what is the meaning of "'FlaskDB' object has no attribute ‘sequences'"? What should I do?
Thanks for your help!
It seems that your User model doesn't have correct database.
With FlaskDB, your User model should inherit FlaskDB().Model
instead of defining class Meta: database = database.
database = FlaskDB()
class User(database.Model):
pass
I want to perform a redirect in one of my view, and I'm facing an error with not many details.
My urls.py:
urlpatterns = [
url(
regex=r'^(?P<pk>[0-9]+)/$',
view=views.SheetDetailView.as_view(),
name='detail'
),
url(
regex=r'^(?P<pk>[0-9]+)/branch/(?P<branch_slug>[a-zA-Z0-9-]+)/$',
view=views.SheetDetailView.as_view(),
name='detail'
),
]
My view
class SheetDetailView(LoginRequiredMixin, UserIsLinkedToSheetMixin, UserPassesTestMixin, DetailView):
model = Sheet
def get_context_data(self, **kwargs):
context = super(SheetDetailView, self).get_context_data(**kwargs)
#if no branch is requested, show the master
if 'branch_slug' in self.kwargs:
branch = self.get_object().get_branch(self.kwargs['branch_slug'])
context['branch']=branch
return context
else:
# redirect to master
sheet_id = self.get_object().pk
branch_slug = self.get_object().get_master().slug
return redirect(reverse('sheets:detail', kwargs={'pk':sheet_id, 'branch_slug':branch_slug}), permanent=False)
And my error message:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 230, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/usr/local/lib/python3.5/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.5/site-packages/six.py", line 686, in reraise
raise value
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 174, in get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/site-packages/django/core/handlers/base.py", line 172, in get_response
response = response.render()
File "/usr/local/lib/python3.5/site-packages/django/template/response.py", line 160, in render
self.content = self.rendered_content
File "/usr/local/lib/python3.5/site-packages/django/template/response.py", line 137, in rendered_content
content = template.render(context, self._request)
File "/usr/local/lib/python3.5/site-packages/django/template/backends/django.py", line 92, in render
context = make_context(context, request)
File "/usr/local/lib/python3.5/site-packages/django/template/context.py", line 291, in make_context
context.push(original_context)
File "/usr/local/lib/python3.5/site-packages/django/template/context.py", line 61, in push
return ContextDict(self, *dicts, **kwargs)
File "/usr/local/lib/python3.5/site-packages/django/template/context.py", line 20, in __init__
super(ContextDict, self).__init__(*args, **kwargs)
ValueError: dictionary update sequence element #0 has length 0; 2 is required
When I print out the reverse() result and paste it into my browser, everything is OK.
You're trying to return a redirect from get_context_data. But that method is supposed to return a context for rendering a template, as the name implies. You probably need to put that particular piece of logic in get or dispatch instead.
I'm currently using #receiver to add a token to new users like so -
#receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
What I also want to be able to do is create a default WidgetList based on this model:
class WidgetList(MPTTModel):
name = models.CharField(max_length=100)
description = models.CharField(max_length=1024)
owner = models.ForeignKey('MyAppUser')
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
def __str__(self):
return self.name
class MPTTMEta:
order_insertion_by = ['name']
I tried making another reciever -
#receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_root_list(sender, instance=None, created=False, **kwargs):
if created:
WidgetList.objects.create(user=instance)
EDIT - on the initial python manage.py migrate I get the following traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 226, in handle
emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/management/sql.py", line 280, in emit_post_migrate_signal
using=db)
File "/opt/myproject_app/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
response = receiver(signal=self, sender=sender, **named)
File "/opt/myproject_app/lib/python2.7/site-packages/guardian/management/__init__.py", line 39, in create_anonymous_user
user.save()
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/base.py", line 734, in save
force_update=force_update, update_fields=update_fields)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/base.py", line 771, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/opt/myproject_app/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
response = receiver(signal=self, sender=sender, **named)
File "/opt/myproject/core/models.py", line 18, in create_root_list
WidgetList.objects.create(user=instance)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/query.py", line 346, in create
obj = self.model(**kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/mptt/models.py", line 393, in __init__
super(MPTTModel, self).__init__(*args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/base.py", line 480, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'user' is an invalid keyword argument for this function
this is the second traceback if I try to rerun migrate:
Traceback (most recent call last):
File "/opt/myproject_app/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/viewsets.py", line 87, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework_encrypted_lookup/views.py", line 41, in dispatch
return super(EncryptedLookupGenericViewSet, self).dispatch(request, *args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/views.py", line 466, in dispatch
response = self.handle_exception(exc)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/views.py", line 463, in dispatch
response = handler(request, *args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/mixins.py", line 21, in create
self.perform_create(serializer)
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/mixins.py", line 26, in perform_create
serializer.save()
File "/opt/myproject_app/lib/python2.7/site-packages/rest_framework/serializers.py", line 191, in save
self.instance = self.create(validated_data)
File "/opt/myproject/api/serializers.py", line 106, in create
validated_data['parent'] = WidgetList.objects.get(pk=user_parent_list)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/myproject_app/lib/python2.7/site-packages/django/db/models/query.py", line 334, in get
self.model._meta.object_name
DoesNotExist: WidgetList matching query does not exist.
Comparing your traceback and your code, you can find that error happens here:
WidgetList.objects.create(user=instance)
Your model WidgetList doesn't even have user field, so it's pretty obvious that you cannot do that. Maybe you were copying & paste the code that caused an error.
There is no user in your model. Which I see you mean owner.
You will get foreign key ref errors as there is not data. Load some parent data using fixture. That would solve this issue.
This is my first night playing around with Google App Engine with djangoforms rather than straight Django. I don't understand why this happens with db.DateTimeProperty().
import datetime
from google.appengine.ext import db
class BoringOldEvent(db.Model):
"""Models an individual Event that someone creates"""
creator = db.StringProperty()
date_created = db.DateTimeProperty(auto_now_add=True)
start_date_time = db.DateTimeProperty()
Will crash if start_date_time = db.DateTimeProperty() does not have auto_now_add=True.
I'm sure there is a good reason, but I"m left scratching my head at the moment because surely users expect to enter datetimes at some point....
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 187, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 225, in _LoadHandler
handler = __import__(path[0])
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
description)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/Users/mw/Documents/yayimin/main.py", line 8, in <module>
import events.views
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
description)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/Users/mw/Documents/yayimin/events/views.py", line 13, in <module>
class EventForm(djangoforms.ModelForm):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/djangoforms.py", line 772, in __new__
form_field = prop.get_form_field()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/djangoforms.py", line 353, in get_form_field
return super(DateTimeProperty, self).get_form_field(**defaults)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/djangoforms.py", line 200, in get_form_field
return form_class(**defaults)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/forms/fields.py", line 394, in __init__
super(DateTimeField, self).__init__(*args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/forms/fields.py", line 99, in __init__
widget = widget()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/forms/widgets.py", line 414, in __init__
self.format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/utils/formats.py", line 67, in get_format
if use_l10n or (use_l10n is None and settings.USE_L10N):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_1_3/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
INFO 2012-08-19 05:07:06,936 dev_appserver.py:2952] "GET /create/ HTTP/1.1" 500 -
Super duper thanks in advance!
It depends whether you're using Python 2.5 or 2.7. If you're using 2.7, you need to set the DJANGO_SETTINGS_MODULE variable in your app.yaml:
env_variables:
DJANGO_SETTINGS_MODULE: 'myapp.settings'
See the Django notes.