I've been searching for a good hour or two for this but I haven't found anything to what I'm looking for.
I'm making a chat application( socket server made in Python ) and it's working fine. The main chat area where messages are stored use HTML, it just displays the username in bold along with their avatar and message. The problem I'm having is how do I stop the user from entering HTML and messing with the main chat? I'm currently using regex "/<.*?>/g" to remove HTML tags however I'd rather let the user send things like
<p>Hi everyone</p>
but instead of parsing what was sent as HTML just normal text?
For example, right now. While a user is typing I'm using regex to remove
<whatever>
tags as soon as they're typed. What I want is for the user to be able to type
<b>bold text</b>
and send but not display it as bold and show the b tags.
Here's what "mainChat" text box looks like http://prntscr.com/46hd4t, this stores all messages
Here's what "chatMessage" text box looks like http://prntscr.com/46hdc6, this is where the user writes their message
Sites such as reddit and Stack Overflow use a standard called markdown for editing text that takes care of these issues. Some popular options for markdown editors include WMD, markitup and Epic Editor. Just Google markdown there are many options to choose from.
Related
I am developing a location based web app/website. The website involves an HTML webpage, which has a button which when clicked by the user should:
Extract the user location coordinates
Run a python Program whose input will be the extracted user location, perform some manipulation.
Finally display real-time results back to the html webpage/ i.e. user computer screen.
The python Program is currently accepting the user location by using geocoder function. The program is successfully running on my system/PC.
I have an AWS EC2 Ubuntu server, to which the location of the vehicle GPS device is being sent.
Finally once everything is set up, I will be hosting/deploying the website so that individual users can test it on their system. I am aware of the hosting part.
Can someone please tell me how do I get along with the task of running the python program on an HTML button click and sending back real time results (which is the output of the python program) back to the html webpage?
To run python code on a buttonClick, you can set a href attribute to a link, which you catch in your flask backend. For example <a href="http://myapp/runthiscode"/> in the HTML and app.rout("/runthiscode") in flask. After that, the manipulation, you can give the updated variables to the page, by redirecting with redirect("/", args=args). args are the updated variables, which you can use in the HTML. For example like this: <a> {{ args }} </a>
The simplest way I can think of doing this is creating a basic API endpoint to do this data processing and return it to your frontend.
The process will look like:
User clicks button
Grab the user's longitutde and latitude (most likely using this, though from the sounds you might be able to do this already)
Submit a POST request to your Flask backend
Render the response in the frontend
Jonas answer gives you a rough sense of what this would look like; the only thing I would add is a tutorial. This one from FreeCodeCamp looks great.
I have a Python script that accepts text from a user, interprets that text and then produces a text response for that user. I want to create a simple web interface to this Python script that is accessible to multiple people at once. By this I mean that person A can go to the website for the script and begin interacting with the script and, at the same time, person B can do the same. This would mean that the script is running in as many processes/sessions as desired.
What would be a good way to approach this?
Maybe you should try a python web framework like django or flask .etc
Make a simple website that offers a webpage that contians a form to input text ,and when people visit the url, put their text in the form and submit, your code can handle it and return a webpage to show the result.
I'm currently setting up email verification for my website that is working with google app engine. I want the users to click a verification link and I would also like to style the email a little using html and css.
So I have my python script all set up. And I have a mail objekt and I do this:
mail.send_mail(sender="...",
to=".....",
subject="Verification Mail"
body="""
Dear ....
Thanks for signing up on example.com
Please click the link below to verify your email adress.
http://example.com/verifymail?email="""+adress+""""&hash="""+hash+"""
We hope you enjoy our platform.
""")
Now this works perfectly fine.
But what I would like is to place an anchor tag inside my mail like
<a href='http://example.com/verifymail?email="""+adress+""""&hash="""+hash+"""'>Verify Email</a>
But doing that will literally print out the html source inside the mail, instead of understanding this as HTML. (It correctly fills in the variables btw). I would also like to add some more things to the newsletter but I guess getting it to understand the tags at all would solve all my problems.
Is there any solution to this?
The reason that your email is interpreted as plain text instead of HTML is that body is interpreted as plain text.
In order for your content to be interpreted as HTML, you will need to set the html attribute as the HTML version of the email, i.e. add something like html="<h3>Hello World</h3>". Check the official API for reference: https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.mail
More background about content type: some email clients cannot interpret HTML messages, so usually both HTML and plain text version are sent to the user to guarantee compatibility. That's why an email has both "plain text" and "HTML" fields.
Can I have any highlight kind of things using Python 2.7? Say when my script clicking on the submit button,feeding data into the text field or selecting values from the drop-down field, just to highlight on that element to make sure to the script runner that his/her script doing what he/she wants.
EDIT
I am using selenium-webdriver with python to automate some web based work on a third party application.
Thanks
This is something you need to do with javascript, not python.
[NOTE: I'm leaving this answer for historical purposes but readers should note that the original question has changed from concerning itself with Python to concerning itself with Selenium]
Assuming you're talking about a browser based application being served from a Python back-end server (and it's just a guess since there's no information in your post):
If you are constructing a response in your Python back-end, wrap the stuff that you want to highlight in a <span> tag and set a class on the span tag. Then, in your CSS define that class with whatever highlighting properties you want to use.
However, if you want to accomplish this highlighting in an already-loaded browser page without generating new HTML on the back end and returning that to the browser, then Python (on the server) has no knowledge of or ability to affect the web page in browser. You must accomplish this using Javascript or a Javascript library or framework in the browser.
I have a script that runs at evening, it writes to a log file as it runs, and once the task completes, the text it writes is also emailed to me. Sometimes the task can fail, what I want to happen is when I get the email, the line with the error is red and bold.
So my question is, can Python format text to a certain font or color if certain conditions are met? If so, are there any good examples?
Thanks!
I think you could just add html tags to your email and send it as HTML. However it'll change the content of your text file as it'll write additional characters to change the styling.
EXAMPLE:
Sending HTML email using Python