2014-05-09 83 views
4

我有一个django web服务,它在本地完美运行,但只要我将它上传到heroku,当我尝试发布帖子时,不断收到405错误,无论我在哪里发帖。 我已将csrf_exempt添加到我的所有帖子视图中。这些都是基于课堂的观点。 例如:405使用django在heroku上不允许使用POST方法

class ApplyForRental(View): 
    def post(self, request, rentalID): 
     #user = User.objects.filter(pk = rentalID) 
     #filtered = Contentfile.objects.filter(file_owner = user, published=True) 
     rental = RentProperty.objects.get(pk = rentalID) 
     applicant = User.objects.get(pk=request.POST.get('interested_renter')) 
     rental.interested_renters.add(applicant) 

     jsonDict = {"success":True} 
     data = json.dumps(jsonDict) 

     return HttpResponse(data, content_type='application/json') 

    @csrf_exempt 
    def dispatch(self,*args,**kwargs): 
     return super(ApplyForRental, self).dispatch(*args,**kwargs) 

任何理由它不会在Heroku上工作,但会在当地工作?

我的网址文件: 主要

urlpatterns = patterns('', 
    # Examples: 
    # url(r'^$', 'homerun.views.home', name='home'), 
    # url(r'^blog/', include('blog.urls')), 
    url(r'^rentals/', include('rentals.urls', namespace="rentals")), 
    url(r'^users/(?P<userID>\w+)/$', views.UserInfo.as_view(), name='getUser'), 
    (r'^grappelli/', include('grappelli.urls')), 
    url(r'^admin/', include(admin.site.urls)), 
) 

应用

urlpatterns = patterns('', 

    url(r'^create/$', views.CreateRental.as_view(), name='createRental'), 
    url(r'^(?P<rentalID>\w+)/$', views.RentalInformation.as_view(), name='getrental'), 
    url(r'^users/(?P<userID>\w+)/$', views.UserRentals.as_view(), name='userrentals'), 
    url(r'^(?P<rentalID>\w+)/uploadimage/$', views.UploadImage.as_view(), name='uploadimage'), 
    url(r'^(?P<rentalID>\w+)/apply/$', views.ApplyForRental.as_view(), name='applyforrental'), 
    url(r'^$', views.RentalsList.as_view(), name='getRentals'), 


    #url(r'^filesInfoByOwner/(?P<userName>\w+)/pk/(?P<pk>\d+)/$', views.FileInfo.as_view(), name='filesByOwnerAndPK'), 
    #url(r'^filesContentByOwner/(?P<userName>\w+)/pk/(?P<pk>\d+)/$', views.GetFileContent.as_view(), name='fileContent'), 

) 

非职位工作的非本地。

+0

请发表您的相关网址的conf,以及URL你试图张贴到。 –

+0

@YuvalAdam添加了urls.py –

回答

0

我不知道这是否是错误的确切原因,但在实例方法上使用装饰器时,必须将其包装在@method_decorator调用中。所以,你的派遣函数应该是这样的,而不是:

from django.utils.decorators import method_decorator 

@method_decorator(csrf_exempt) 
def dispatch(self,*args,**kwargs): 
    return super(ApplyForRental, self).dispatch(*args,**kwargs) 

https://docs.djangoproject.com/en/1.7/topics/class-based-views/intro/#decorating-the-class