Pergunta

I am trying to to redirect some of my Django views to https, using the SSLRedirect middleware.

I created the middleware, but I'm having trouble securing specific url paths as described in the middleware snippet. When I add {'SSL':True} to my view keywords, I get this syntax error: 'non-keyword arg after keyword arg'. My urls.py is

from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import direct_to_template

from post.views import *

urlpatterns = patterns('',      
    url(r'^$', turk_post, name='post', {'SSL':True}),
)
Foi útil?

Solução

Replace:

url(r'^$', turk_post, name='post', {'SSL':True}),

with:

url(r'^$', turk_post, name='post', kwargs={'SSL':True}),

The Django url is a function defined like this:

def url(regex, view, kwargs=None, name=None, prefix=''):
    # et cetera

(hence your error as the function expects a keyword argument)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top