mac os sierra

时间:2017-05-03 10:10:51

标签: python mysql html5 localhost

我正在使用谷歌地图,其中有一个基本表格供用户填写他的详细信息。在单击提交时,表单详细信息将被存储在我创建的MySQL表中。

我正在使用已预先安装在我的mac上的apache。 我已经下载了MySQL并且运行正常。我创建了包含所需列的表。 我正在使用PyCharm Community Edition来运行我的python脚本。

我的map.html文件(带有表单的谷歌地图的文件)在localhost上正常运行。 但是,在单击提交时,我收到以下错误: 未找到 在此服务器上找不到请求的URL /Library/WebServer/CGI-Executables/processing.py。

我的map.html文件位于Library / WebServer / Documents /

#map.html file

<!DOCTYPE html>
<html>
   	<head>
	   	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    	<meta charset="utf-8" />
		<title>MAPS</title>

		<style>
			#map {
				width: 100%;
				height: 100%;
			}

			html, body {
			    height: 100%;
			    margin: 0;
			    padding: 0;
			}

			#description {
			    font-family: Calibri;
			    font-size: 15px;
			    font-weight: 300;
			}

			#infowindow-content .title {
			    display: none;
			}

			
			#map #infowindow-content {
			    display: none;
			}

			.pac-card {
			    margin: 10px 10px 0 0;
			    border-radius: 2px 0 0 2px;
			    box-sizing: border-box;
			    -moz-box-sizing: border-box;
			    outline: none;
			    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
			    background-color: #fff;
			    font-family: Calibri;
			}

			#pac-container {
			    padding-bottom: 12px;
			    margin-right: 12px;
			}

			.pac-controls {
			    display: inline-block;
			    padding: 5px 11px;
			}

			.pac-controls label {
			    font-family: Calibri;
			    font-size: 16px;
			    font-weight: 400;
			}

		    #pac-input {
		        background-color: #fff;
		        font-family: Calibri;
		        font-size: 15px;
		        font-weight: 400;
		        margin-left: 12px;
		        padding: 8px 12px;
		        text-overflow: ellipsis;
		        width: 400px;
		        border: 1px solid #ccc;
		    }

		    #pac-input:focus {
		        border-color: #4d90fe;
		    }

		    #title {
		        color: #fff;
		        background-color: #4d90fe;
		        font-size: 25px;
		        font-weight: 400;
		        padding: 6px 12px;
		    }

		    #target {
		    	width: 345px;
		    }

		    #form
			{
				display: none;
			}

		    #heading {
			    text-align: center;
			    color: #003366;
			    font-size: 30px;
			    font-family: Calibri;
			    padding: 8px 12px;
			}

		    label.field {
			    text-align: left;
			    font-weight: bolder;
			    font-size: 16px;
			    font-family: Calibri;
			}

			input[type=text], input[type=email], input[type=number], select {
			   	font-family: Calibri;
			   	font-size: 16px;
			   	font-weight: bolder;
			   	padding: 8px 12px;
			   	width: 100%;
    			margin: 8px 0;
    			display: inline-block;
    			border: 1px solid black;
    			border-radius: 4px;
    			box-sizing: border-box;
			}

			input[type=submit] {
				font-family: Calibri;
				font-size: 16px;
				font-weight: bolder;
    			background-color: white;
    			color: #00b300;
    			padding: 8px 12px;
    			margin: 8px 0;
    			border: 2px solid #00b300;
    			border-radius: 4px;
    			cursor: pointer;
    			box-sizing: border-box;
			}

			input[type=submit]:hover {
    			background-color: #00b300;
    			color: white;
    		}

    		input[type=reset] {
    			font-family: Calibri;
    			font-size: 16px;
    			font-weight: bolder;
    			background-color: white;
    			color: #cc0000;
    			padding: 8px 12px;
    			margin: 8px 0;
    			border: 2px solid #cc0000;
    			border-radius: 4px;
    			cursor: pointer;
    			box-sizing: border-box;
			}

			input[type=reset]:hover {
    			background-color: #cc0000;
    			color: white;
    		}

    		input[type=text]:focus {
    			background-color: #f2f2f2;
    			border-color: #4d90fe;
    		}

    		input[type=email]:focus {
    			background-color: #f2f2f2;
    			border-color: #4d90fe;
    		}

    		input[type=number]:focus {
    			background-color: #f2f2f2;
    			border-color: #4d90fe;
    		}

    		select:focus {
    			background-color: #f2f2f2;
    			border-color: #4d90fe;
    		}
		</style>

		<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC8EAfEQrYVs4c_kMBUQw3tVY8uhEViDCU&libraries=places&callback=initAutocomplete"
                async defer>
        </script> 	
			
	</head>

	<body>
		<div id="map"></div>
		<input id="pac-input" class="controls" type="text" placeholder="Search your location..." />
		<div id="form">
			<form action="Library/WebServer/CGI-Executables/processing.py" method="post">
    		<p id="heading">PERSONAL INFORMATION</p>
  			<label class="field" for="fullname"><b>Full Name:</b></label>
  			<input type="text" name="fullname" placeholder="Eg. Suraj Makhija" size="30" required />
  			<br />
  			<br />
  			<label class="field" for="emailid"><b>E-mail:</b></label>
  			<input type="email" name="emailid" placeholder="Eg. contact@domain.com" size="30" required />
  			<br />
  			<br />
  			<label class="field" for="mobile"><b>Mobile:</b></label>
  			<input type="text" name="mobile" placeholder="Eg. 9999999999" maxlength="10" minlength="10" size="30" required />
  			<br />
  			<br />
  			<label class="field" for="gender"><b>Gender:</b></label>
  			<select name="gender" required>
    			<option value="male">Male</option>
    			<option value="female">Female</option>
    			<option value="other">Other</option>
  			</select>
  			<br />
  			<br />
  			<label class="field" for="areaofexpertise"><b>Area of Expertise:</b></label>
  			<input type="text" name="areaofexpertise" placeholder="Eg. Android/iOS Developer" size="30" required />
  			<br />
  			<br />
  			<label class="field" for="yearsofexperience"><b>Years of Experience:</b></label>
  			<input type="number" name="yearsofexperience" placeholder="Eg. 10" min="0" max="100" required />
  			<br />
  			<br />
  			<p style="text-align: center;">
  			<input type="submit" value="Submit" /> 
  			<input type="reset" value="Clear All" /> 
  			</p>
        	</form>
        </div>

		<script>
			var map;
			var iconBase;
			var input;
			var searchBox;	 
			var markers=[]; 		
      		var markerArray =[];
      		var infowindow;
      		
		    function initAutocomplete() {
        		map = new google.maps.Map(document.getElementById('map'), {
          			center: {lat: 20.5937, lng: 78.9629},
          			zoom: 5,
         			mapTypeId: 'roadmap',
         			gestureHandling: 'cooperative'
        		});

        	//Declaring infowindow.
        	infowindow = new google.maps.InfoWindow({
          		content: document.getElementById('form')
        	});

            // Create the search box and link it to the UI element.
        	input = document.getElementById('pac-input');
        	searchBox = new google.maps.places.SearchBox(input);
        	map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

            // Bias the SearchBox results towards current map's viewport.
        	map.addListener('bounds_changed', function() {
          		searchBox.setBounds(map.getBounds());
        	});

        	//Creates a marker when the user clicks on a location on the map.
        	google.maps.event.addListener(map, 'click', function(event) {
		        addMarker(event.latLng, map);
		    });

            // Listen for the event fired when the user selects a prediction and retrieve
            // more details for that place.
        	searchBox.addListener('places_changed', function() {
          		var places = searchBox.getPlaces();
          		if (places.length == 0) {
            		return;
         		}

            // Clear out the old markers.
          	markers.forEach(function(marker) {
            	marker.setMap(null);
          	});
          			
            // For each place, get the icon, name and location.
          	var bounds = new google.maps.LatLngBounds();
          	places.forEach(function(place) {
            	if (!place.geometry) {
              		console.log("Returned place contains no geometry");
              		return;
            	}
            var icon = {
              	url: place.icon,
              	size: new google.maps.Size(71, 71),
              	origin: new google.maps.Point(0, 0),
              	anchor: new google.maps.Point(17, 34),
              	scaledSize: new google.maps.Size(25, 25)
            };
			// Create a marker for each place.
		    markers.push(new google.maps.Marker({
		        map: map,
		        icon: icon,
		        title: place.name,
		        position: place.geometry.location
		    }));
		    if (place.geometry.viewport) {
		    // Only geocodes have viewport.
		        bounds.union(place.geometry.viewport);
		        } else {
		        bounds.extend(place.geometry.location);
		        }
		    });
		    map.fitBounds(bounds);
		    });
		}

			//Marker function declaration.
			function addMarker(location, map) {
		    // Add the marker at the clicked location.
		    	var iconBase = 'https://maps.google.com/mapfiles/kml/paddle/';
		        marker = new google.maps.Marker({
		        draggable: true,
	    		animation: google.maps.Animation.DROP,
		        position: location,
		        map: map,
		        icon: iconBase + 'ylw-blank.png'
		    });
		    //Infowindow pops up on clicking the marker.
		    google.maps.event.addListener(marker, 'click', function() {
		    	document.getElementById('form').style.display='inline-block';
            	infowindow.open(map, marker);
          	});
		}
		</script>

	</body>
</html>

我的processing.py文件(用于处理表单数据和插入MySQL表的python脚本)在Library / WebServer / CGI-Executables /

除了将.py添加到AddHandler语句之外,我没有对我的httpd.conf文件进行任何更改。

我在下面附上我的所有文件。

请帮助我,因为我已经被困在这一段很长一段时间了。 请注意我使用Mac OS Sierra。

提前致谢。

#processing.py file 

import MySQLdb

import cgi

import cgitb

cgitb.enable()

form = cgi.FieldStorage()

fullname = form.getvalue('fullname', '')

emailid = form.getvalue('emailid', '')

mobile = form.getvalue('mobile', '')

gender = form.getvalue('gender', '')

areaofexpertise = form.getvalue('areaofexpertise', '')

yearsofexperience = form.getvalue('yearsofexperience', '')

db = MySQLdb.connect(host="localhost", user="root", passwd="*****", db="client_database")

cursor = db.cursor()

query = """INSERT INTO client_info (FULL_NAME, EMAIL_ID, MOBILE, GENDER, AREA_OF_EXPERTISE, YEARS_OF_EXPERIENCE) 
    VALUES (%s, %s, %s, %s, %s, %s)"""

cursor.execute(query, (fullname, emailid, mobile, gender, areaofexpertise, yearsofexperience))

result = cursor.fetchall()

db.commit()

db.close()

0 个答案:

没有答案