javascript - Tranforming buttons - works in development, not deployment -


i have sign out form. users click button secure reservation. button changes “free” “reserved”, reserved button includes user’s name. i’m using django, added js button change without refresh.

this works fine on local server, when deploy pythonanywhere doesn’t. instead, button transforms, displays “none” , console check “undefined”.

any idea went wrong?

abridged code below:

main.js $( 'button' ).click(function() {         console.log( 'we clicked!' ); // sanity check ii         var pk = this.id         var button = $(this)         var user = $( 'button' ).attr("user")         console.log( pk, user) // sanity check iii $.ajax({             url: "/reserve/",             type: "post",       //send info reserve view             data: { pk : pk},             success: function(data) {                 var number = json.parse(data);                 console.log(number, number.result)                 if (number.result == 1 ) {                       if (number.result == 2) {              console.log(user)              $(button).toggleclass( "free reserved")              $(button).children("div.tchr").html(user);   //send user info button, reverts on refresh                 $.toast({                     heading: "reservation complete!",                     icon: 'success',                     stack: 4,                     hideafter: 2000                 });             } 

and button

home.html  {% p in periods %}             <td class="slots">                 period {{p}} <br>{% x in this_week %} {% d=x.day|date:"w" %} {% if d == '1' , x.period == p %} {% if x.is_reserved == true %} # this_week  queryset of reservations, day day converted weekday                 <button id="{{x.pk}}" type="submit" class="reserved btn">                                 <span class="cart">{{x.cart}}</span>                                 <div class="tchr" style="text-align:left">{{x.teacher}}</div></button> {% else %}                 <button id="{{x.pk}}" type="submit" user="{{request.user }}" class="free btn">{% csrf_token %}                                 <span class="cart">{{x.cart}}</span>                                 <div class="tchr">{{x.teacher}}</div></button> {% endif %} {% endif %} {% endwith %} {% endfor %}             </td>             {% endfor %} 

there few more options (cleared, reserved, blocked)

again, works fine in development! missing?

you need serve static files.

javascript files count static files. in development environment, when debug set true inside settings.py files, django takes car of collecting static files , serving them, when turn debug false in deployment server stops.

take @ staticfiles app documentation on django project know how use it. simple static files server can use.

to make sure problem, navigate settings.py file , turn debug true restart server. if works expected, follow instructions on link above.

make sure not rely on debug mode since cause performance degradation , massive memory leaks


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -