URL-адрес, который я пытаюсь найти:
http://domain/games/getdata/genres/
Этот запрос сделан через ajax для получения некоторых данных JSON из внешнего API. Я не могу заставить это сделать совпадение; продолжает работать с обработчиком промежуточного программного обеспечения, который я настроил. Я уверен, что это исправление довольно очевидно, но я слишком долго смотрел на это.
urls.py:
from django.conf import settings
from django.conf.urls.defaults import patterns, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', 'blog.views.index'),
(r'^games/$', 'giantbomb_games.views.index'),
(r'^games/getdata/(?P<resource>\w+)/$', 'giantbomb_games.views.getdata'),
(r'^grappelli/', include('grappelli.urls')),
(r'^admin/filebrowser/', include('filebrowser.urls')),
(r'^admin/', include(admin.site.urls)),
)
views.py:
def getdata(request, resource):
url = '%s/%s/?api_key=%s&format=%s' % (api_url, resource , api_key, request_format)
print url
r = requests.get(url)
return r.content
страница / middleware.py:
from django.http import Http404
from django.conf import settings
from page.views import site_page
class SitePageFallbackMiddleware(object):
def process_response(self, request, response):
if response.status_code != 404:
return response # No need to check for a flatpage for non-404 responses.
try:
return site_page(request, request.path_info)
# Return the original response if any errors happened. Because this
# is a middleware, we can't assume the errors will be caught elsewhere.
except Http404:
return response
except:
if settings.DEBUG:
raise
return response
Ошибка Django:
Traceback (most recent call last):
File "/var/www/html/top10/top10/../ext/django/core/servers/basehttp.py", line 280, in run
self.result = application(self.environ, self.start_response)
File "/var/www/html/top10/top10/../ext/django/core/servers/basehttp.py", line 674, in __call__
return self.application(environ, start_response)
File "/var/www/html/top10/top10/../ext/django/core/handlers/wsgi.py", line 245, in __call__
response = middleware_method(request, response)
File "/var/www/html/top10/top10/page/middleware.py", line 8, in process_response
if response.status_code != 404:
AttributeError: 'str' object has no attribute 'status_code'
Заранее спасибо.