In my python for Google App Engine, I have this
MAIN_PAGE_FOOTER_TEMPLATE = """\
<form action="/sign?%s" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<hr>
<form>Guestbook name:
<input value="%s" name="guestbook_name">
<input type="submit" value="switch">
</form>
</body>
</html>"""
which is used in these functions
self.response.write('<html><body>')
self.response.write(MAIN_PAGE_FOOTER_TEMPLATE %
(sign_query_params, cgi.escape(guestbook_name)))
So I understand that the %s in the top code takes in the parameters provided at the bottom code. However, I am unsure as to how I can do this in a HTML file, rather than coding in python, as it becomes very messy if the HTML code is long. Can anyone help me?
Related
what is the proper way to parse multiple .html files within directory, search and remove part of html code in these files?
For example, I need to remove a html code from all files:
<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>
I use Geany 1.29 file editor on Debian. Regex is probably not suitable for this. Some shell script or python?
You can use htql, for example:
html = """
something before
<div class="box">
<h2>Book Search</h2>
<div id="search">
<form action="http://www.biology35.com/search.php" method="post">
<input type="text" name="searchfor" class="txtField" />
<input type="image" src="new/images/btn-go.png" name="Submit" value="Submit" class="button" />
<div class="clear"><!-- --></div>
</form>
</div>
</div>
html after
"""
import htql
x=htql.query(html, "<div norecur (class='box') > &delete ")[0][0]
You get:
>>> x
'\nsomething before\n \n\nhtml after\n'
I want to add styling to the below form (main objective is to change the text color of placeholder as my form is of dark color and the placeholder is not visible due to its default gray color) I am sure there must be some way to achieve this in the template only.
Snippet from CSS
::placeholder {
color: aquamarine;
opacity: 1;
}
Snippet from Template
<form action="{% url 'register' %}" class="box" method="POST">
<input type="text" name="username" placeholder="{{form.username.label}}" id=""/>
<input type="text" name="firstname" placeholder="{{form.first_name.label}}" id="" />
<input type="text" name="lastname" placeholder="{{form.last_name.label}}" id=""/>
<input type="text" name="email"placeholder="{{form.email.label}}"id="" />
<input type="text" name="password1" placeholder="{{form.password1.label}}" id=""/>
<input type="text" name="password2" placeholder="{{form.password2.label}}" id=""/>
<input type="submit" value="Submit" />
</form>
This is my form that I have created to add a new user (django.contrib.auth.models User). I am not sure how do I use {{form.username}} in the existing form. If I simply put {{form.username}} to the form it is creating a new field without any styling applied to it.
Maybe I misunderstood what you want to achieve, but you can simply set custom CSS via <style></style> tag. If you would like to a more sophisticated solution, you can define CSS class in form widget attributes or append custom styles to form.
<style>
::placeholder {
color: aquamarine;
opacity: 1;
}
</style>
<form action="{% url 'register' %}" class="box" method="POST">
<input type="text" name="username" placeholder="{{form.username.label}}" id=""/>
<input type="text" name="firstname" placeholder="{{form.first_name.label}}" id="" />
<input type="text" name="lastname" placeholder="{{form.last_name.label}}" id=""/>
<input type="text" name="email"placeholder="{{form.email.label}}"id="" />
<input type="text" name="password1" placeholder="{{form.password1.label}}" id=""/>
<input type="text" name="password2" placeholder="{{form.password2.label}}" id=""/>
<input type="submit" value="Submit" />
</form>
I found a dirty fix for the problem. I first entered made the form like below -
<form action="{% url 'register' %}" class="box" method="POST">
{{form.username}}
{{form.first_name}}
...
</form>
Then I inspected the rendered template and stole the HTML equivalent of the above code. I have added the all the required attributes in the input tags. It looks like below snippet -
{% csrf_token%}
<input
type="text"
name="username"
maxlength="150"
**placeholder="Username"**
autofocus=""
required=""
id="id_username"
/>
<input
type="text"
name="first_name"
maxlength="30"
**placeholder="First Name"**
id="id_first_name"
/>
...
I know this probably is not a perfect solution and there must be a more elegant way of handling this scenario. However, I am going ahead with this approach for time being as it is serving the purpose.
<html>
<head>
<title>Insert Data into DB</title>
</head>
<body>
<hl><br>Insert Data into DB</hl>
<form method="post" action="" name="form1">
<fieldset>
<legend>Slot Status</legend>
<label>slot:<input type="text" name="fname" /></label>
<label>status:<input type="text" name="lname" /></label>
</fieldset>
<br />
<input type="submit" name="submit" value="Update Slot Status" />
</form>
</body>
</html>
Sir above is a simple html form I made and i want to fill this form using python Script.Especially I want to use the mechanize module. Any help will be highly appreciated. Thank You.
I'm working with the guestbook example. I added a button type="file" for choosing a file, but I can't seem to be able to upload that to the datastore. Here is what code I have for the button:
self.response.out.write("""
<form action="/sign?%s" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div>Select a file to upload:<input name="content" type="file" value="file"></div>
<div><br><input type="submit" value="Upload a File"></div>
</form>
<form method="get" download="file">
<button type="submit">Download</button>
</form>
<hr>
<form>Name: <input value="%s" name="gae_name">
<input type="submit" value="switch"></form>
</body>
</html>""" % (urllib.urlencode({'gae_name': gae_name}),
cgi.escape(gae_name)))
I would like if the "Upload a File" button, uploaded it to the datastore like the textarea does. But i can't seem to be able to do that, or find any sample code anywhere.
The relevant part of my flask code is:
#app.route("/process", methods = ["GET", "POST"] )
def process_form():
#checked = request.form.getlist('option')
checked=request.form('option')
with open('checked.txt','w') as file:
file.write("%s"%checked)
# do something with checked array
return checked
and my html looks like:
<div class="container" id='tog'>
<div class="half">
<form action="/process" method="POST">
<input type="radio" name="option" value="original" />
<h3>originak value<h3>
</div>
<div class="half">
<input type="radio" name="option" value="freq" />
<h3>Term Freq<h3>
</div>
</form>
</div>
The idea is that I want to find out which radio button was selected and store the information is a text file. But that does not seem to be working.
I changed the html to:
<form action="/process" method="POST">
<div class="half">
<input type="radio" name="option" value="original" />
</div>
<div class="half">
<input type="radio" name="option" value="freq" />
</div>
<input type="submit" value="Submit">
</form>
and now I get a 400 Bad Request error
You don't have a submit button inside of your form. Add one.
<input type="submit" value="Submit!" />
Also, you probably want to change request.form('option') to request.form['option']