Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

calling a python script form jQuery in MAMP

I am trying to setup a local environment on my mac so I have installed MAMP.

I am using the following code to call a python file that I have written, but all it does is output the text of my .py file, it doesnt actually execute it.

What am I doing wrong?

$.ajax({method: "POST",
                url: "../python/newsletter.py",
                data: {email: $("form input").val()}
            })
            .done(function( msg ) {
                alert( "Data Saved: " + msg );
            });

2 Answers

Steven Parker
Steven Parker
243,318 Points

I'm not familiar with MAMP, but it looks like the server is just delivering the referenced python file instead of processing it.

Just a guess - but could you have overlooked something in the server configuration that would cause requested files of that type to be implicitly passed through the python interpreter instead of being handled like generic content?

Yeah. I am definitely missing something, I'm just not sure what yet. I have scrapped MAMP and have gone for an apache setup. The python file I am calling is literally just "print('hello')", just as a trial to see if I can get it to work.

I'm very stuck!