小编use*_*554的帖子

405 POST方法不允许

我正在尝试使用OAuth开发REST提供程序.我正在使用Django RESTFramework和DjangoOAuthToolkit.我做了一个GET并且它工作得很好但是我正在尝试使用POST而服务器响应{"detail":"方法'POST'不允许."}这是我的代码:

# views.py
@api_view(['POST'])
def pruebapost(request):
    usuario = User()
    access_token = Token.objects.get(
        key=request.POST['oauth_token']
    )
    usuario = access_token.user
    content = {'saludo': usuario.username}
    return Response(content)

# settings.py
OAUTH_AUTHORIZE_VIEW = 'principal.views.oauth_authorize'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
REST_FRAMEWORK = {
   'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
    ),
   'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.JSONParser',
    ),
   'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.OAuthAuthentication',
    ),
}
Run Code Online (Sandbox Code Playgroud)

我正在使用它作为"测试"客户端:

import urlparse
import oauth2 as oauth
import requests

consumer_key = "clave"
consumer_secret = "secreto"
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
resource_url = 'http://blablabla.pythonanywhere.com/prueba'
consumer = oauth.Consumer(key='clave', secret='secreto')
token = oauth.Token(key='e7456187a43141af8d2e0d8fa99b95b9', …
Run Code Online (Sandbox Code Playgroud)

django post oauth http-status-code-405 django-rest-framework

38
推荐指数
2
解决办法
7万
查看次数

计数器在for-each中,position()没用

如何在XSLT中使用不使用position()的计数器?例如:XML

<product type="A" name="pepe"/>
<product type="B" name="paco"/>
<product type="A" name="Juan"/>
<product type="B" name="Edu"/>
<product type="A" name="Lauren"/>
Run Code Online (Sandbox Code Playgroud)

我想按顺序显示所有类型"A":

1.pepe
2.Juan
3.Lauren
Run Code Online (Sandbox Code Playgroud)

xsl就是这样的

<xsl:for-each select="./products">
<xsl:if test="./products/product/@type="A"">
                    <tr>
<xsl:value-of select="position()"/>
<xsl:value-of select="./product/@name"/>  
                    </tr> 
</xsl:if>  
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)

xml xslt

2
推荐指数
1
解决办法
8283
查看次数