Django requests with ajax -


i working on simple mvc application have submit forms ajax. create class purpose manage requests specific module

class produto(view):     template_name = 'produto/index.html'      def get(self, request):         context = {             'modulos': cello_apps,             'modulo': 'produtos'         }          return render(request, self.template_name, context)      def post(self, request):          if request.is_ajax() , request.method == "post":             return jsonresponse({'foo': 'bar'})         else:             raise http404 

this looks pretty logical me, doesn't work , raise error

missing 1 required positional argument: 'request'

the way solve problem setting post method static

class produto(view):     template_name = 'produto/index.html'      def get(self, request):         context = {             'modulos': cello_apps,             'modulo': 'produtos'         }          return render(request, self.template_name, context)  def post(request):      if request.is_ajax() , request.method == "post":         return jsonresponse({'foo': 'bar'})     else:         raise http404 

so have 2 doubts:

1- how can create single class many functions accessible ajax?

2- best or recommended way manage views? (considering application can grow lot in future)

edit.

here follows urls.py

urlpatterns = [     url(r'^inserir', produto.inserir, name='produto_inserir'),     url(r'^$', produto.as_view(), name='cliente'), ] 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -