2016-08-14 3 views
1

Ich habe Probleme, die CSS richtig zu verknüpfen. Es ist richtig benannt. Es will einfach nicht funktionieren. Ich habe alles versucht, um es zu tippen. Ich habe eine Menge verschiedener Dinge gehört. Einige sagen, dass Sie die gesamte Projekt-URL eingeben müssen (simple-login/css/style.css). Ich habe auch gehört, dass du nur eine Stufe höher gehen musst (../css/style.css). Ich habe auch gehört, dass du das nicht tun musst (css/style.css). Nichts scheint zu funktionieren. Es funktioniert immer in normalen HTML-Dateien. Muss ich etwas importieren? Ich bin wirklich frustriert. Ich sollte das CSS nicht direkt in dieses Projekt einbetten. Es muss eine separate Datei sein.Python - CSS funktioniert nicht in Embedded HTML

import webapp2 #Use the webapp2 Library 

class MainHandler(webapp2.RequestHandler): #declaring a class 
    def get(self): 
     if self.request.GET: #variables that store the information from the forms. This information will be used in the write() method to put the information on the page. Parts of the html, stored in variables, are strung together in the write() method. 
      user = self.request.GET['user'] 
      email = self.request.GET['email'] 
      games = self.request.GET['games'] 
      city = self.request.GET['city'] 
      state = self.request.GET['state'] 
      gender = self.request.GET['gender'] 
      self.response.write(Page.interface_head + Page.interface_body + Page.interface_info + Page.info_name + user + '</br>' + Page.info_email + email + '</br>' + Page.info_games + games + '</br>' + Page.info_city + city + ', ' + state + '</br>' + Page.info_gender + gender + Page.info_close + Page.interface_closing) 
     else: #This is what the write method does when there is no response to the request. Meaning this is the page you are met with in the beginning. Parts of the html, stored in variables, are strung together in the write() method. 
      self.response.write(Page.interface_head + Page.interface_body + Page.interface_forms + Page.interface_closing) 

class Page(object): 
     interface_head = '''<!Doctype HTML> <!--This houses all code in the head of my HTML including the style portion.--> 
<html> 
    <head> 
     <title>Simple Form</title> 
     <link href="css/style.css" rel="stylesheet" type="text/css"/> 
    </head> 
    <body>''' 

     interface_body = '''<nav><h2>Game<span>Stuff</span></h2></nav> <!--This is the code for the nav all the way down to the forms.-->''' 

     interface_info = '''<div class='info_background'> <!--This is the start of the div that houses the information entered from the forms. Below are all the labels split up into vriables. This is for organization and will be reassembled in the if and else statement.--> 
      <h3>Is this information correct?</h3>''' 
     info_name = '''<label>Name: </label>''' 
     info_email = '''<label>Email: </label>''' 
     info_games = '''<label>Favorite Games: </label>''' 
     info_city = '''<label>City/State: </label>''' 
     info_gender = '''<label>Gender: </label>''' 
     info_close = ''' 
     </br><button>Yes</button><button>No</button></div>''' 
     interface_forms = '''<form method='GET'><!--These forms enter the information to be stored in the variables in the if statement.--> 
      <h3>Sign Up for a free account!</h3> 
      <label>Name: </label><input type='text' name='user' /> 
      <label>Email: </label><input type='text' name='email' /></br> 
      <label>Favorite Games: </label><input type='text' name='games' /> 
      <label>City: </label><input type='text' name='city' style='width: 120px;' /> 
      <label>State: </label><select name='state'> 
      <option value="AL">Alabama</option> 
      <option value="AK">Alaska</option> 
      <option value="AZ">Arizona</option> 
      <option value="AR">Arkansas</option> 
      <option value="CA">California</option> 
      <option value="CO">Colorado</option> 
      <option value="CT">Connecticut</option> 
      <option value="DE">Delaware</option> 
      <option value="DC">District Of Columbia</option> 
      <option value="FL">Florida</option> 
      <option value="GA">Georgia</option> 
      <option value="HI">Hawaii</option> 
      <option value="ID">Idaho</option> 
      <option value="IL">Illinois</option> 
      <option value="IN">Indiana</option> 
      <option value="IA">Iowa</option> 
      <option value="KS">Kansas</option> 
      <option value="KY">Kentucky</option> 
      <option value="LA">Louisiana</option> 
      <option value="ME">Maine</option> 
      <option value="MD">Maryland</option> 
      <option value="MA">Massachusetts</option> 
      <option value="MI">Michigan</option> 
      <option value="MN">Minnesota</option> 
      <option value="MS">Mississippi</option> 
      <option value="MO">Missouri</option> 
      <option value="MT">Montana</option> 
      <option value="NE">Nebraska</option> 
      <option value="NV">Nevada</option> 
      <option value="NH">New Hampshire</option> 
      <option value="NJ">New Jersey</option> 
      <option value="NM">New Mexico</option> 
      <option value="NY">New York</option> 
      <option value="NC">North Carolina</option> 
      <option value="ND">North Dakota</option> 
      <option value="OH">Ohio</option> 
      <option value="OK">Oklahoma</option> 
      <option value="OR">Oregon</option> 
      <option value="PA">Pennsylvania</option> 
      <option value="RI">Rhode Island</option> 
      <option value="SC">South Carolina</option> 
      <option value="SD">South Dakota</option> 
      <option value="TN">Tennessee</option> 
      <option value="TX">Texas</option> 
      <option value="UT">Utah</option> 
      <option value="VT">Vermont</option> 
      <option value="VA">Virginia</option> 
      <option value="WA">Washington</option> 
      <option value="WV">West Virginia</option> 
      <option value="WI">Wisconsin</option> 
      <option value="WY">Wyoming</option> 
     </select> 
     <label>Gender: </label><input type="radio" name="gender" value="Male"> Male 
     <input type="radio" name="gender" value="Female"> Female 
     <input type="radio" name="gender" value="Other"> Other 
     <input type="submit" value='Create Account'/> <!--This submit button finalizes all the information put in the forms.--> 
     </form>''' 

     interface_closing = ''' 
      <footer>&copy;Made by Matt Lee</footer> <!--This is a footer I made just so there was something final on the page.--> 
    </body> 
</html>''' 

app = webapp2.WSGIApplication([ 
    ('/', MainHandler) 
], debug=True) 
+0

Was ist Ihr Rahmen? Mit einer WSGI-App können statische Dateien möglicherweise nicht bereitgestellt werden. Du brauchst vielleicht so etwas wie nginx –

+0

Dies ist nur reguläres Python im Google App Engine Launcher. Keine Rahmen. –

+1

Warum verwenden Sie keine Vorlagen? Sie sollten HTML in Python nicht aufbauen. –

Antwort

0

Ich würde vorschlagen, dass Sie Jinja 2 verwenden. Es wird Ihnen helfen, Ihren Code zu organisieren. Es ist eine Vorlagensprache, die wirklich gut mit Webapp2 verwendet werden kann.