1
votes

The function in my mobx store is being called but axios cant find my django function.

store.jsx

import { autorun, observable, action, computed } from 'mobx';
import axios from 'axios'; 

axios.defaults.xsrfHeaderName = "X-CSRFToken";

class ProductyTypeStore {
  @observable producttypelist = [];

  @action addProductType(description){
  	 console.log("before store add");
    axios.post('/addproducttype/')
        .then(function( res ){
          console.log(res);
        }) // then
        .catch(function(err){
        	console.log(err);
        })
        console.log("after store add");

  }
}

var store1 = window.store = new ProductyTypeStore

export default store1

urls.py

urlpatterns = [
url(r'^', erp, name="erp"),
url(r'^addproducttype/$', addProductType, name = "addProductType")

]

views.py

def erp(request):
context = {}
template = 'index.html'
return render( request, template, context )

def addProductType(request):
print("here @ add")

log on my manage.py runserver

--Starting development server at http://127.0.0.1:8000/ --Quit the server with CONTROL-C. --[30/Mar/2017 03:51:19] "GET / HTTP/1.1" 200 524 --[30/Mar/2017 03:51:19] "GET /static/bundles/local/vendors.js HTTP/1.1" 200 366564 --[30/Mar/2017 03:51:19] "GET /static/bundles/local/erp-2a384599697b15811b6c.js HTTP/1.1" 200 2088371 --[30/Mar/2017 03:51:22] "POST /addproducttype/ HTTP/1.1" 200 524

My print("here @ add") in the django view is never printed. I have no idea whats wrong with my code.

1

1 Answers

0
votes

It turns out that it has something to do with my URLS.PY configuration. It should be url(r'^$', erp, name="erp") instead of url(r'^', erp, name="erp").