我已经看到人们在尝试发出远程Ajax请求时遇到禁止错误的情况,但是我正在做一个本地请求,我也在我的中间件中打开了CSRF.
errorThrown返回"Forbidden"
我认为问题可能是我正在尝试将其发送到普通视图(当前页面)...我不确定我的预处理器是否返回到视图以重新呈现页面..或者如果它是返回我当前的页面.(不要以为我解释得那么好)
希望这能为您提供足够好的照片.任何/所有帮助表示赞赏.
.ajax:
jQuery.ajax({
type: "POST",
dataType: "json",
data: dataString,
success: function(json) {
jQuery(".signup").attr('disabled', false);
$('.success').show();
console.log(json.message);
},
error: function(jqXHR, textStatus, errorThrown) {
jQuery(".signup").attr('disabled', false);
$('.fail').show().append(errorThrown);
console.log(textStatus);
}
});
Run Code Online (Sandbox Code Playgroud) 我试图在 Django 中分解以下代码,以弄清楚它在做什么,并在必要时对其进行编辑,但我不太清楚其中一些函数在做什么或它们来自哪里。
test_func 和 view_func 是 Django 特定的还是这些内置的 python 函数?
结论: 我不确定我如何/为什么忽略了这些只是被定义为函数的参数这一事实。我需要开始更加关注细节。
这是我试图分解/弄清楚的 Django 函数:
def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Decorator for views that checks that the user passes the given test,
redirecting to the log-in page if necessary. The test should be a callable
that takes the user object and returns True if the user passes.
"""
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
print test_func
if test_func(request.user):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri()
# If …Run Code Online (Sandbox Code Playgroud) 我希望我的应用程序的仪表板区域被称为 /console。但是,Flask 使用 werkzeug.debug.DebuggedApplication ( http://werkzeug.pocoo.org/docs/debug/ ),它使用 /console 作为默认调试路径。Flask 本身只有调试标志,
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
没有其他选项可以覆盖该路径。我有哪些选择?
我暂时添加了以下内容,但我不想这样做,因为我在前端的 JS 中发生了一些复杂的事情,例如注册期间的重定向等。
if app.debug:
app.register_blueprint(.., url_prefix='/con')
else:
app.register_blueprint(..., url_prefix='/console')
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码,我无法弄清楚为什么当urlopen()失败时它不会引发异常.
在我的特殊情况下,我知道为什么它失败..我的网址没有http://在他们面前...但我想抓住这些情况,以便脚本可以继续运行我的代码而不是退出.
req = urllib2.Request(link)
try:
url = urllib2.urlopen(req)
except urllib2.URLError, e:
print e.code
print e.read()
return False
Run Code Online (Sandbox Code Playgroud)
而我正在......
Traceback (most recent call last):
File "./getURLs.py", line 141, in <module>
main()
File "./getURLs.py", line 82, in main
Process(args).get_children()
File "./getURLs.py", line 65, in get_children
self.get_links(link)
File "./getURLs.py", line 46, in get_links
data = urllib2.urlopen(req)
File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/local/lib/python2.7/urllib2.py", line 383, in open
protocol = req.get_type()
File "/usr/local/lib/python2.7/urllib2.py", line 244, in get_type
raise …Run Code Online (Sandbox Code Playgroud) 这不是第一次发生在我身上,所以现在我正在寻找答案,因为我完全难过了.
我现在已经在生产环境中运行了3个多月的代码并且它工作得非常好,然后我开始在python中出现错误.
'method_descriptor' object has no attribute 'today'
Exception Value:
'method_descriptor' object has no attribute 'today'
Exception Location: /admin/views/create.py in process, line 114
/admin/views/create.py in process
order = Orders(uid=0, accepted=0, canview='', files=0, date=datetime.date.today(), due=dueDate,
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在使用以下内容,它在python shell中运行得非常好:
>>> import datetime
>>> datetime.date.today()
>>> datetime.date(2011, 9, 27)
Run Code Online (Sandbox Code Playgroud) 我正在尝试找出确切请求的位置/时间.用户成为AnonymousUser.我一直在搜索整个Auth后端,但我似乎无法找到它.我在找错了地方吗?
我知道每个不是Authenticated用户的用户都会成为AnonymousUser,但我需要知道我正在构建的某些代码在何处/何时发生.
任何帮助,将不胜感激.
我正在使用现有的数据库作为我最新的Django项目,所以除非我改变我的模型或Django auth代码,否则将两者合并起来相当困难.
而不是搞乱现有的auth后端,我打算只编写自己的身份验证应用程序.
无论如何,我以前的所有身份验证应用程序都是用PHP编写的,基本上我只是将所有内容都放在会话变量中并在每个页面上验证它们......这就是我有点困惑的事情.看来,当用户通过身份验证/登录时,会将整个用户添加到会话中,但我无法确定其发生的位置或方式.
在默认的Django登录功能中,它将用户分配给request.user ...这是以某种方式保存为会话变量还是只是传递到下一个视图?如果它只是被传递到下一个视图,未来的请求如何进行身份验证而不需要进一步的登录请求?
默认的Django auth登录名在下面..
def login(request, user):
"""
Persist a user id and a backend in the request. This way a user doesn't
have to reauthenticate on every request.
"""
if user is None:
user = request.user
# TODO: It would be nice to support different login methods, like signed cookies.
if SESSION_KEY in request.session:
if request.session[SESSION_KEY] != user.id:
# To avoid reusing another user's session, create a new, empty
# session if the existing session …Run Code Online (Sandbox Code Playgroud)