首页 \ 问答 \ 无法在Django中获取AngularJS的$ http.post数据(Cant get AngularJS's $http.post data in Django)

无法在Django中获取AngularJS的$ http.post数据(Cant get AngularJS's $http.post data in Django)

我知道这是一个非常基本的问题,但在浪费了我一整天后,我都在问这个问题。 我只是使用以下AngularJS代码向Django发送数据:

$http.post('/data/creation', 
                    {
                html: 'a'

            }).
              success(function(data, status, headers, config) {
                // this callback will be called asynchronously
                // when the response is available
                  console.log(data);
                  console.log(status);
                  console.log(headers);
                  console.log(config);
              }).
              error(function(data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                  console.log(status);
                  console.log(data);
              });

在django:

@csrf_exempt
def snippets_post(request):
    html = False
    css = False
    js = False
    JSONdata = False
    response = "You're looking at the results of question %s."
    if request.method == 'POST':
        try:
            JSONdata = request.POST.get('data', False) # it was [] in actual
        except:
            JSONdata = 'ERROR'

    return HttpResponse(JSONdata)

我得到False作为回应, “通过在POST中将数据替换为html。结果是相同的” 。 我不知道这里出了什么问题。 任何人都可以帮我这个吗?

谢谢


I know its a very basic question but after wasting my whole day I am asking this. I am just sending data using following AngularJS code to Django:

$http.post('/data/creation', 
                    {
                html: 'a'

            }).
              success(function(data, status, headers, config) {
                // this callback will be called asynchronously
                // when the response is available
                  console.log(data);
                  console.log(status);
                  console.log(headers);
                  console.log(config);
              }).
              error(function(data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                  console.log(status);
                  console.log(data);
              });

and in django:

@csrf_exempt
def snippets_post(request):
    html = False
    css = False
    js = False
    JSONdata = False
    response = "You're looking at the results of question %s."
    if request.method == 'POST':
        try:
            JSONdata = request.POST.get('data', False) # it was [] in actual
        except:
            JSONdata = 'ERROR'

    return HttpResponse(JSONdata)

I am getting False as response, "by replacing data to html in POST.get result is same". I don't know whats going wrong here. Can any one help me here on this?

Thanks


原文:https://stackoverflow.com/questions/26742922
更新时间:2022-05-17 13:05

最满意答案

在此问题得到解决之前,有两种方法可以解决此问题:

  1. 使用Azure AD PowerShell,您可以禁用然后删除应用程序角色。 这是一个可以实现此目的的示例脚本:

    $appId = "83d7d56d-6e64-4791-b8e8-9a8da8dd957e"
    $appRoleValue = "app-role-value" # i.e. the scope
    
    Connect-AzureAD
    
    # Disable the AppRole
    $app = Get-AzureADApplication -Filter "appId eq '$appId'"
    ($app.AppRoles | Where-Object { $_.Value -eq $appRoleValue }).IsEnabled = $false
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $app.AppRoles
    
    # Remove the AppRole
    $toRemove = $app.AppRoles | Where-Object { $_.Value -eq $appRoleValue }
    $app.AppRoles.Remove($toRemove) | Out-Null
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $app.AppRoles
    
  2. 另一种选择是使用Azure AD Graph Explorer并在Application对象上发出两个PATCH请求。 第一个PATCH请求应将app角色的isEnabled属性设置为false 。 然后,第二个PATCH请求可以删除app角色(即包括除已禁用的角色之外的所有现有app角色)。


Until this gets fixed, there two options to work around this issue:

  1. Using Azure AD PowerShell, you can disable and then remove the app role. Here's a sample script that would achieve this:

    $appId = "83d7d56d-6e64-4791-b8e8-9a8da8dd957e"
    $appRoleValue = "app-role-value" # i.e. the scope
    
    Connect-AzureAD
    
    # Disable the AppRole
    $app = Get-AzureADApplication -Filter "appId eq '$appId'"
    ($app.AppRoles | Where-Object { $_.Value -eq $appRoleValue }).IsEnabled = $false
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $app.AppRoles
    
    # Remove the AppRole
    $toRemove = $app.AppRoles | Where-Object { $_.Value -eq $appRoleValue }
    $app.AppRoles.Remove($toRemove) | Out-Null
    Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $app.AppRoles
    
  2. An alternative option is to user the Azure AD Graph Explorer and issue two PATCH requests on the Application object. The first PATCH request should set the app role's isEnabled attribute to false. The second PATCH request can then remove the app role (i.e. include all existing app roles except the disabled one).

相关问答

更多
  • 没有! Windows Azure Active Directory不是域控制器。 您不能将计算机加入Windows Azure AD。 您可以使用它将本地AD与Windows Azure AD同步,以轻松启用Web SSO(单一登录)。 您可以使用它来构建企业级Web应用程序。 您可以在这里阅读有关Windows Azure Active Directory的更多信息。 NO! Windows Azure Active Directory is NOT a Domain Controller. You c ...
  • 在此问题得到解决之前,有两种方法可以解决此问题: 使用Azure AD PowerShell,您可以禁用然后删除应用程序角色。 这是一个可以实现此目的的示例脚本: $appId = "83d7d56d-6e64-4791-b8e8-9a8da8dd957e" $appRoleValue = "app-role-value" # i.e. the scope Connect-AzureAD # Disable the AppRole $app = Get-AzureADApplication -Filte ...
  • 不,使用Azure AD提供的功能无法连接互联网是不可能的。 可以在VirtualBox中创建一个本地虚拟机,并包含所有必需的AD功能,然后切换软件以在开发模式下使用本地虚拟机,但在发布模式下使用Azure AD? 如果要使用身份验证,则在脱机工作时可能需要设置自己的身份提供程序服务器。 有许多开源库可以帮助设置身份提供商服务器,如IndentyServer , AspNet.Security.OpenIdConnect.Server等。 No, it is impossible to use the fe ...
  • 在Azure Active Directory中,用户同意被注册为用户对象和表示客户端应用程序的服务主体对象之间的链接。 此链接在AAD Graph API中表示为OAuth2PermissionGrant 你说的这个: 现在,该用户所做的是从Azure AD手动删除我们的应用程序(再次通过“应用程序”选项卡)。 根据我们对同意模型的理解,这意味着用户已取消对我们的申请的同意。 我想澄清一下。 您可能知道,在创建新的AAD应用程序时,需要记住应用程序对象和服务主体之间的区别。 具体而言,如果您删除代表客户端 ...
  • 你的问题很广泛,由几个问题组成,因此很难简明扼要地回答。 如果您的用户已经在您的Azure AD中,则应该将其用作用户存储。 但是,如果它们不在您的组织之中,则可以使用Azure AD B2C,其中包含用于创建自助式帐户的功能。 或者查看https://stackoverflow.com/a/16068340 ,了解如何为公共用户使用AAD的建议。 如果用户已经存在于您的AAD中,并且您尚未在AAD中的应用程序上设置用户分配,则他们可以登录到应用程序。 如果您对此有兴趣,您可以使用基于角色的安全性为用户授予 ...
  • 我终于找到了答案。 为了从ServicePrincipal获取AppRoleAssignments,您需要直接查询列表,而不是尝试将其从ServicePrincipal扩展: await client.ServicePrincipals .GetByObjectId(servicePrincipalObjectId) .AppRoleAssignedTo .ExecuteAsync() 然后,您必须手动浏览用户和组以获取最终用户列表。 这可能会导致许多Graph API服务调用,具 ...
  • Azure Active Directory不支持LDAP协议,因此您将无法使用.NET的System.DirectoryService类。 AAD服务使用称为Graph API的东西来查询目录数据。 这是一个基于REST的Web API。 http://msdn.microsoft.com/en-us/library/windowsazure/hh974476.aspx 如果要通过AAD进行身份验证,可以使用ADAL库: http://msdn.microsoft.com/en-us/library/wi ...
  • 2016年9月更新 :现在可以从新门户中选择无限到期日期。 在幕后,它实际上并不是无限的,但它确定了未来很远的日期。 来源: https : //stephaneeyskens.wordpress.com/2016/01/14/managing-expiration-of-azure-active-directory-application-client-secrets/ Update September 2016: it is now possible to chose an infinite expir ...
  • 我理解这一点的方式是Azure AD(用户管理,计费管理等)中的角色仅适用于Azure AD。 它们与订阅角色(您在Azure门户中设置的角色,如所有者,贡献者,读者)无关。 您需要做的是在旧门户中的Azure AD中创建这些用户后,返回Azure门户并根据您的要求为这些用户分配订阅角色。 一旦这些人员分配了订阅角色,他们就应该能够访问Azure门户。 您可能会发现此链接对分配订阅角色很有用: https : //azure.microsoft.com/en-in/documentation/article ...
  • Azure Active Directory是一种多租户服务,可为云应用程序提供身份和访问管理。 它与Server Active Directory不同,也不是在Azure中的虚拟机中运行的Windows Server AD实例。 所以,回答你的问题 - 没有。 如果您希望服务器AD的实例测试LDAP查询,则可以在虚拟机中旋转一个。 您需要将其放入虚拟网络中。 此外,创建虚拟机的实例以在要测试的应用程序上运行应用程序。 本教程应该为您解决。 http://www.windowsazure.com/en-us ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)