virtualenvで実行される単純なDjangoアプリ(1.3.1)を作成しています。WebFactionで稼働しています。Flatpagesの使用のみを保証するのに十分シンプルです-FlatPagesに加えたい拡張機能がまだ少しあるので、モデルを拡張するだけです-複雑なことは何もありません。
models.py
from django.db import models
from django.contrib.flatpages.models import FlatPage
class ExtendedFlatPage(FlatPage):
order = models.PositiveIntegerField(unique=True)
class Meta:
ordering = ["order"]
verbose_name = "Page"
問題はログアウトに関係しています。エントリポイントからサイトにログアウトしようとしても問題はありません。つまり、http:// {domainname} / admin / logout /ですが、管理サイト内からシステムからログアウトしようとすると、例です。拡張FlatPageshttp:// {domainname} / admin / basic / extendedflatpage /のリスト内にある場合、ログアウト(http:// {domainname} / admin / basic / extendedflatpage / logout /)はエラーを生成し、最終観測
ValueError:10進数のint()のリテラルが無効です:'logout'
エントリの下部にある完全なトレースバック。
urls.py
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}),
)
インターネットで探し回ると、次のページに修正の提案が表示されました。問題は、これを機能させることができないようです-これを実装しようとした方法は、urls.pyを次のように調整することでした:
...
admin.autodiscover()
admin.site.root_path = '/admin/' #should this go here?
urlpatterns = patterns('',
...
トレースバック
Traceback (most recent call last):
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/contrib/admin/options.py", line 307, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/views/decorators/cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 197, in inner
return view(request, *args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/transaction.py", line 217, in inner
res = func(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/reversion/revisions.py", line 279, in do_revision_context
return func(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/reversion/admin.py", line 362, in change_view
return super(VersionAdmin, self).change_view(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/utils/decorators.py", line 28, in _wrapper
return bound_func(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/utils/decorators.py", line 24, in bound_func
return func(self, *args2, **kwargs2)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/transaction.py", line 217, in inner
res = func(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/contrib/admin/options.py", line 947, in change_view
obj = self.get_object(request, unquote(object_id))
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/contrib/admin/options.py", line 451, in get_object
return queryset.get(pk=object_id)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/query.py", line 341, in get
clone = self.filter(*args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/query.py", line 550, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1194, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1129, in add_filter
connector)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/sql/where.py", line 67, in add
value = obj.prepare(lookup_type, value)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/sql/where.py", line 316, in prepare
return self.field.get_prep_lookup(lookup_type, value)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/fields/related.py", line 136, in get_prep_lookup
return self._pk_trace(value, 'get_prep_lookup', lookup_type)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/fields/related.py", line 209, in _pk_trace
v = getattr(field, prep_func)(lookup_type, v, **kwargs)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 292, in get_prep_lookup
return self.get_prep_value(value)
File "/home/niceguydave/.virtualenvs/iwama/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 479, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'logout'
<WSGIRequest
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{'csrftoken': '7cad0c7ee5b93f897e82934aac3f9224',
'sessionid': 'b7440ccc530704ca15b315f8f1f9f7ed'},
META:{'CSRF_COOKIE': '7cad0c7ee5b93f897e82934aac3f9224',
'DOCUMENT_ROOT': '/usr/local/apache2/htdocs',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'sessionid=b7440ccc530704ca15b315f8f1f9f7ed; csrftoken=7cad0c7ee5b93f897e82934aac3f9224',
'HTTP_HOST': 'www.iwamaaikidocornwall.com',
'HTTP_HTTPS': 'off',
'HTTP_HTTP_X_FORWARDED_PROTO': 'http',
'HTTP_REFERER': 'http://www.iwamaaikidocornwall.com/admin/basic/extendedflatpage/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/4.1.3 Safari/533.19.4',
'HTTP_X_FORWARDED_FOR': '89.241.106.48',
'HTTP_X_FORWARDED_HOST': 'www.iwamaaikidocornwall.com',
'HTTP_X_FORWARDED_PROTO': 'http',
'HTTP_X_FORWARDED_SERVER': 'www.iwamaaikidocornwall.com',
'HTTP_X_FORWARDED_SSL': 'off',
'PATH_INFO': u'/admin/basic/extendedflatpage/logout/',
'PATH_TRANSLATED': '/home/niceguydave/webapps/iwama/production.wsgi/admin/basic/extendedflatpage/logout/',
'QUERY_STRING': '',
'REMOTE_ADDR': '127.0.0.1',
'REMOTE_PORT': '40468',
'REQUEST_METHOD': 'GET',
'REQUEST_URI': '/admin/basic/extendedflatpage/logout/',
'SCRIPT_FILENAME': '/home/niceguydave/webapps/iwama/production.wsgi',
'SCRIPT_NAME': u'',
'SERVER_ADDR': '127.0.0.1',
'SERVER_ADMIN': '[no address given]',
'SERVER_NAME': 'www.iwamaaikidocornwall.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SIGNATURE': '',
'SERVER_SOFTWARE': 'Apache/2.2.17 (Unix) mod_wsgi/3.3 Python/2.7.3',
'mod_wsgi.application_group': 'web318.webfaction.com|',
'mod_wsgi.callable_object': 'application',
'mod_wsgi.handler_script': '',
'mod_wsgi.input_chunked': '0',
'mod_wsgi.listener_host': '',
'mod_wsgi.listener_port': '47425',
'mod_wsgi.process_group': 'iwama',
'mod_wsgi.request_handler': 'wsgi-script',
'mod_wsgi.script_reloading': '1',
'mod_wsgi.version': (3, 3),
'wsgi.errors': <mod_wsgi.Log object at 0x7f5a450c8f30>,
'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f5a44eb2828>,
'wsgi.input': <mod_wsgi.Input object at 0x7f5a44e833b0>,
'wsgi.multiprocess': True,
'wsgi.multithread': True,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 1)}>
2012年5月7日更新
私はここの投稿でいくつかの観察を行い、修正のためにアプリに適用し、拡張されたFlatpageアプリ内に新しいビューを作成しました
views.py
def logout(request):
from django.contrib.auth.views import logout
return logout(request)
次に、このビューをurls.pyにインポートし、これを呼び出しています
urls.py
...
from basic.views import logout as custom_logout
...
urlpatterns = patterns('',
url(r'/logout/$', custom_logout),
url(r'^admin/', include(admin.site.urls)),
...
これで問題は解決しましたが、「パッチを適用」しているように見えます。
誰かがこれを行うためのより良い方法を提案できますか?それとも、ここで適用したパッチは合理的なことのように思われますか?