我收到此消息:
CSRF令牌丢失或不正确.
在大多数论坛中,告诉你在表单中获取{%csrf_token%},我确实拥有它.
我也在我的settings.py中:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.csrf",
"django.contrib.auth.context_processors.auth",
)
Run Code Online (Sandbox Code Playgroud)
我正在使用jinja,它似乎没有使用CSRF,但后来我安装了django注册而我迷路了,因为,它似乎正在使用其他一些观点,我无法访问,所以说,它们是不是我写的,我无法弄清楚他们在哪里.他们称之为"标准认证视图".所以我无法添加"RequestContext".
任何想法发生了什么以及我如何能够实现目标?感谢名单
我正在使用django-registration,只是设置它.
{{user.is_authenticated }}
Run Code Online (Sandbox Code Playgroud)
是的,即使我已经去了/ accounts/logout /并将用户注销了.
{{user.is_anonymous }}
Run Code Online (Sandbox Code Playgroud)
也返回true.根据django docs的说法,这两者应该是不同的:
is_anonymous:始终返回False.这是区分User和AnonymousUser对象的一种方法.通常,您应该更喜欢将is_authenticated()用于此方法.
和
is_authenticated:始终返回True.这是一种判断用户是否已通过身份验证的方法.这并不意味着任何权限,也不会检查用户是否处于活动状态 - 它仅表示用户提供了有效的用户名和密码.
我正在使用django-registration附带的标准视图,但尚未触及它们.在tempalate我有以下代码:
{% if user.is_authenticated %}
{% user }}
{% if user.is_anonymous %}
is anonymous
{% endif $}
{% else %}
gotta login
{% endif %}
Run Code Online (Sandbox Code Playgroud)
问题出在哪里?我会非常感激的!
更新:我注意到在主页上,它都是is_authenticated,id_anonymous返回True,而如果我在登录前进入/ accounts/login,只有is_anonymous返回true应该是.而且,在主页上,如果有帮助,我有以下视图:
def home(request):
return render_jinja(request, 'index.html', blah = 'ga')
Run Code Online (Sandbox Code Playgroud)
更新2:print(request.user.is_authenticated())给出False.然后,我有:
return render_jinja(request, 'index.html', blah = 'ga')
Run Code Online (Sandbox Code Playgroud)
在模板中,user.is_authenticated返回FALSE.
更新3:如果我使用render_to_response而不是render_jinja,一切都很好.仍然不知道如何解决这个问题:(
出于某种原因,django政府在某些时候被打破了.css丢失了.
这是我的设置:
MEDIA_ROOT = os.path.normpath(os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'
Run Code Online (Sandbox Code Playgroud)
但是,管理页面上生成的行仍然是:
<link rel="stylesheet" type="text/css" href="/admin_media/css/base.css" />
Run Code Online (Sandbox Code Playgroud)
但该网站在这个文件上给了我404.
它变得更好 - 如果我使用apache来查看项目,那就会出现问题.如果我使用python manage.py runserver管理员工作得很好.
为什么会发生这种情况的任何线索? - 重启apache,没有帮助.
这是我在urls文件中的内容:
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
Run Code Online (Sandbox Code Playgroud) 我的Ajax调用中包含数据:
data: { hint: {'asdf':4} },
Run Code Online (Sandbox Code Playgroud)
我觉得我应该能够访问这个对象
request.POST['hint'] # and possibly request.POST['hint']['asdf'] to get 4
Run Code Online (Sandbox Code Playgroud)
但这个错误会妨碍你.我看着
MultiValueDictKeyError at /post_url/
"'hint'"
Run Code Online (Sandbox Code Playgroud)
当我打印帖子数据时,我得到了奇怪的错误字典:
<QueryDict: {u'hint[asdf]': [u'4']}>
Run Code Online (Sandbox Code Playgroud)
我应该如何正确传递数据,所以我在Python中保留了相同的结构并使用它与我在JS中的方式相同?
我有两台服务器,但运行的设置大致相同 - IIS、SQL Server 等。一台服务器给我这个错误,另一台则没有。我将相同的代码从 Visual Studio 发布到两者。
他们都在跑步.NET CLR Version v4.0.30319,我相信是这样4.5。
有些答案说你必须瞄准另一个版本,如果我在 Visual Studio 中更改它,一切都会崩溃,所以事实并非如此。此外,相同的代码在其他服务器上运行。
其他答案说一些旧的 DLL 可能是原因。我没有部署到工作服务器,所以也许复制了一些较新的 DLL?但我怎么知道呢?
另外,错误似乎不在我的代码中,而是在框架和 Umbraco 中,所以我认为我不应该进入并更新字符串函数或类似的东西:
[MissingMethodException: Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.]
System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String mediaType, String parameterName) +0
System.Net.Http.Headers.MediaTypeHeaderValue..ctor(String mediaType) +33
System.Net.Http.Formatting.MediaTypeConstants..cctor() +45
[TypeInitializationException: The type initializer for 'System.Net.Http.Formatting.MediaTypeConstants' threw an exception.]
System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() +99
System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() +49
System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) +255
System.Web.Http.GlobalConfiguration.<CreateConfiguration>b__0() +78
System.Lazy`1.CreateValue() +14308960
System.Lazy`1.LazyInitValue() +524
Umbraco.Web.WebBootManager.InitializeResolvers() +1530
Umbraco.Core.CoreBootManager.Initialize() +814
Umbraco.Web.WebBootManager.Initialize() +19
Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e) +244 …Run Code Online (Sandbox Code Playgroud) 我已将模拟器设置为可以工作,我可以在端口 4000 上访问它。我还看到 Firestore 状态为“ON”
但是,当我尝试进行查询时,我得到:
Access to fetch at 'http://localhost:8080/google.firestore.v1.Firestore/Listen/channel?database=projects%2Ffresh-divot%2Fdatabases%2F(default)&VER=8&RID=14788&CVER=22&X-HTTP-Session-Id=gsessionid&%24httpHeaders=X-Goog-Api-Client%3Agl-js%2F%20fire%2F9.6.6%0D%0AContent-Type%3Atext%2Fplain%0D%0A&zx=6jc2pop1rvwd&t=1' from origin 'http://localhost:1234' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
Run Code Online (Sandbox Code Playgroud)
我的设置如下:react web app running on localhost:1234 我的模拟器 firestore running on localhost:8088
我的设置如下:
let config = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_TO,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
databaseURL: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
};
if (location.hostname === "localhost") {
config = …Run Code Online (Sandbox Code Playgroud) 通常我会这样做.htaccess但django没有它.
那么最好的方法是什么,从www.olddomain.com重定向到www.newdomain.com的代码是什么?
注意:我们不使用Apache,而是使用Gunicorn
感谢名单!
我想设置一个组件react-select来处理服务器端数据并进行服务器端过滤,但由于多种原因它不起作用。
您能解释一下并显示工作代码吗?
基本上我想在CakePHP中重新创建它:
换句话说,我的中间表有额外的字段来定义关系的类型.
如何在CakePHP中进行设置?
您可以使用例如:
model company:
id
name
person_id
model person:
id
name
model company_person:
company_id
person_id
position
Run Code Online (Sandbox Code Playgroud)
感谢名单
我经常忘记步骤,希望有一个关于在 Heroku 上部署 django 项目的快速指导指南。
如何在 Heroku 上安装和部署 Django 应用程序?
我已经发布了对我有用的步骤的分步答案。