I like Flask Framework For Web Application – Python Programming

I think Flask is an amazing Python framework because it is versatile and flexible. Although there is a drawback to using Flask instead of Django such as with Flask you have to implement many features that would come out of the box with Django. For example, with Django, you get a really good admin panel without any effort, but with Flask you have to write the whole admin panel yourself using Flask Security or Flask Login with Flask Admin — these packages together can help you to be able to code a completed admin panel that allows an administrator to do backend stuff and maintain the web application. With Django, the admin panel that comes out of the box looks very nice. Somehow though, perhaps I could be wrong but I’ve found Django’s admin panel, even with extensive personal customization, a heavy custom Django admin panel is still looking too similar to the one that comes out of the box. With Flask, since you have to code this yourself and depending on how much time and effort you put into the admin panel, it could look completely alien from one programmer’s Flask admin panel to the next.

I have learned Python for a couple of months or so, and I have found Flask is easier to work with than Django — I fondly remembered I started with Django first — and I had a hard time with making Django’s routing of internal paths to the way I like it. With Flask though, it’s simple as:

@app.route('/')
def home_page():
    custom code goes here
    return render_template('index.html', some_variable_to_pass_into_Jinja2_template=whatever)

The piece of code above would render an index.html page for a website using Flask. The decorator @app refers to the Flask app itself, and the route part is where the custom method home_page would render the template’s index.html page — in this case, the forward-slash (‘/’) would be a shortcut to render the index.html page. Now, let’s say you have a contact page where a web visitor could email you or so, how would you route this?

@app.route('/contact')
def contact_page():
    custom code goes here
    return render_template('contact.html', whatever=whatever, blah=blah, contact_form=contact_form)

So, when a visitor goes to ‘yourwebsite.yourdomain-name/contact — Flask would render the contact.html page.

I like how Flask routes internal paths like this because it’s so easy to see what is going on — not like Django’s black box. If you take a look at the custom code immediately after the @app.route, you would right away know that the block of codes belongs to what template’s page of the website.

I have heard a lot of people loved to use Flask for writing RESTful API, and I actually had done this once as a practice exercise. I could definitely see why people love Flask for this very purpose — it’s so easy to just jsonify the data using Flask. Once you have jsonify the data, you can totally choose how you would like to return these data when a request is made to the app using Flask. Nonetheless, recently I have been using Flask to just create small websites — not RESTful API — and this is fresher in my mind than doing RESTful API.

To sum it up, I just scratch the surface of what Flask can do in this blog post. Based on my own experience, I’ve found Flask is easier to work with than Django. Deploying the Flask web app felt easier than Django too. For example, once I’d finished writing a Flask web app, all I had to do was initialize a GitHub repository, commit, and push the web app to GitHub. Afterward, I could use Heroku or PythonAnywhere to host my Flask web app either through the free tier or paid tier. Setting up Flask with Heroku or PythonAnywhere isn’t that hard. The key is to do a double-check of the requirements.txt to make sure all required packages that Flask needs to run your web app are listed in this file. Heroku and PythonAnywhere rely on this file to install necessary third-party Python packages. Once you set up the necessary steps for Heroku or PythonAnywhere, the last thing you only have to do is to pull your app’s source from GitHub onto Heroku or PythonAnywhere. On Heroku’s CLI, you can just do [git push heroku main], and on PythonAnywhere Bash console you can just do [git pull].

Anywho, I just completed coding a Portfolio website using Flask. The main feature of this website is to allow a user to add various project showcases so he or she can show off the projects. The website relies on Bootstrap 5 and custom CSS I’d written — this means the whole website is responsive to various screen sizes, including mobile phones. In desktop mode, the website showcase two projects one at a time through the pagination feature — allowing visitors to flip to more projects by clicking next or back to previous projects. In mobile mode, I used lazy load to load the first few showcase projects’ images — then the rest would be loaded on-demand as the website visitors could forever scroll downward till all projects had been loaded. Check out the finished product on https://pythongenex.pythonanywhere.com/.

Vidxr, New To Go Place For Music Videos

I’m just releasing Vidxr.com, and this will be the to go personal music video playlist weblog for me.  Of course, while adding more awesome music videos to Vidxr, I hope you can check Vidxr out for some enjoyable music video time.

We’re living in a digital age where most things can be shared digitally.  Vidxr is made possible by content sharing features provided by various online services such as YouTube.  Thanks to these web services, I’m able to form Vidxr.

As time goes on, I hope that I will be able to make Vidxr a very likable music video weblog.  If you like what you’re seeing with Vidxr, please let everyone knows about it.  Thank you very much!

Oneplus.net Is Crashing As Too Many People Are Trying To Pre-Order

Apparently, Oneplus.net is down as it crashes when so many people are hitting Oneplus.net at the same time to pre-order Oneplus One smartphone.  Oneplus.net tweets (link) that its people are working on to bring the server back up for pre-ordering.  As I’m writing this right now, I can’t really pre-oder the phone since Oneplus.net won’t allow my web browser to load it.  Anyhow, let’s hope Oneplus.net will be OK soon so people can begin to pre-order Oneplus One.  I had the feeling that this would happen, because Oneplus One is a hot smartphone.  I didn’t know I was so damn right about that I wouldn’t get to load Oneplus.net correctly on time for pre-ordering. Sigh…  Are you pre-ordering Oneplus One too?

The Reddit’s Oneplus One Pre-order conversation is here (link).

Update:  I finally got through the Oneplus.net’s Pre-order hiccup and ordered 2 Oneplus Ones.  One for my sister, and the other one is for me.  Nonetheless, at the moment, I’m still seeing my payment to Oneplus.net through Paypal is being pending.  Crossing my fingers and hoping that nothing will go wrong.  If nothing will go wrong, I’ll receive Oneplus One in 4 to 5 weeks wait time.  The wait time is suck, but I hope the phone will be great!

Ways To Stay Safe When Connecting To The Internet!!!

A University of Salford exhibition at the Manc...

A University of Salford exhibition at the Manchester Science Festival will follow in the footsteps of Monty Python by asking: “What has the Internet has ever done for us?” The Family Telecommunications Exhibition is showing this weekend and features a collection of artefacts and demonstrations including the Morse telegraph, telephones, mobile phones, home computers, the Internet and much more. (Photo credit: Wikipedia)

Throughout the years, I have came to be very paranoid about how should I protect myself from the bad things that harbor along with the good things on the Internet.  It is never easy to weed out the bad things from the good things, therefore I always on the lookout for newer and better technology to protect myself from all Internet bad things.  To tell the truth, I don’t have anything to protect other than my online financial activities just like everybody does nowadays…  Banking nowadays can be done easily online, but sometimes the insecurity of doing it online can be even more stressful than doing it the traditional way — but nobody is sure that traditional way is anyway safer than banking online… get it?  Anyhow, since I’m so paranoid about online security over the years, to a great discomfort of mine, I think I have knew several ways to stay safe from strangers’ prying eyes when connecting to the Internet.  Of course, there are countless ways to skin this cat, and it’s an ongoing thing, but I have simply pooled the easiest and the most necessary ways that one can stay safe when connecting to the Internet into a video.  I hope this will help anybody who needs some guidance on how to stay safe when connecting to the Internet.  Also, this video will be something that I will gladly tell the people I know in real life who are very much ignorant about their online safety.  The video will prevent me from giving a long boring lecture, because it will be the boring lecture instead of me — avoid the wrath of the people who if ever need my help on online security.  So, if you need any guidance on staying secure when connecting to the Internet, why not check out my video right after the break.  Enjoy!

Compressing A Website To Improve Its Speed

There are many ways to make your website loads faster, but in this blog post, I’ll mention the Zlib compression method for websites that are using PHP (i.e., scripting programming language).  According to what I’ve read so far on the Internet, Zlib not only can compress your PHP website to make it loads faster, it can also greatly reduce the amount of bandwidth that requires of your PHP/Apache server to serve the web requests to web browsers (i.e., website visitors’ browsers).  Of course, I’m not the one who had genuinely come up with this idea, and so I will produce the sources (i.e., on the information I write in this blog post) at the end of this blog post.

To have Zlib compression works for your PHP/Apache website, first you need to make sure that your PHP/Apache web server is actually has configured with Zlib module.  To do this, you can create a phpinfo test page to list the installed Apache and PHP modules.  An example of phpinfo test page can be found here.  To put this another way, you need to create a webpage ends with .php extension, and inside this webpage, you add an opening tag of php, a function of phpinfo (i.e., phpinfo();), and a closing tag of php to completely close the php program; don’t forget to save the php webpage so you can visit it through a browser to pull up the list of installed Apache and PHP modules.

Let say your php info test page confirms that your web server had configured with Zlib module.  Great!  All you have to do is to paste this tidbit of code which can be found here into your webpage, but make sure this very code goes above everything (i.e., above document types).  To put this in another way, you need to create an opening php tag, the php ob_start function (i.e., ob_start(‘ob_gzhandler’);), and to close up everything you add the closing php tag — this very code has to be above everything that resides inside your webpage.

There is another way to enable Zlib compression for your entire website by adding the right elements into your htaccess file.  Nonetheless, I’m still looking for the valid code for htaccess method.  The ob_start method (i.e., calling for ob_gzhandler function) is cumbersome for people who don’t use content management systems (e.g., WordPress, Drupal, etc…), because they have to add the php ob_start function (i.e., to call the ob_gzhandler function) to every webpage that they want to compress.  Luckily for WordPress users and other Content Management Systems’ users, because by adding the ob_start function to the headers of the websites’ templates (e.g., header.php, index.php, etc…) once — it suffices to say that such website owners have sufficiently enabling their websites to be compressed by Zlib.

To test to see if your website is actually compressed or not, you can visit here.  Another method is to download Google’s Page Speed extension for Chrome browser.  I believe Page Speed extension is also available for Firefox browser, but I’m not exactly sure on this.  You can find it out for yourself though!

Update:  Besides using Page Speed extension from your browsers (e.g., Chrome, Firefox), you can visit Page Speed Online to test out your website’s performance at pagespeed.googlelabs.com.

Update:  Also, you can try out webpagetest.org, because I find out this website has incorporated Page Speed into its test results for testing websites’ performances.

Sources:  http://www.desilva.biz/php/zlib.htmlhttp://php.net/manual/en/function.ob-gzhandler.phphttp://www.gidnetwork.com/tools/gzip-test.php.