Skip to main content

Posts

Showing posts with the label fun

Create a URL Shortener app with Python and Django. Part-2

Create a URL Shortener app with Python and Django. Part-2 READ PART 1 :  https://blogofchamodh.blogspot.com/2022/07/create-url-shortener-app-with-python.html READ PART 3:  https://blogofchamodh.blogspot.com/2022/08/create-url-shortener-app-with-python.html Photo by  LinkedIn Sales Solutions  on  Unsplash To start the project you have to use the Django-admin  command. This tutorial series is to teach how to create a URL Shortener app and I don't explain the very basics. Please let me know if you want a primary tutorial series in the comment section below. 1. Starting the project. 2. Starting the app To start a Django app we run the python manage.py [APP_NAME]    command. 2. Register the app To tell Django to consider url_shortener as an app for our project we have to edit the settings.py file inside the Shortener Folder. Add a line in the following format to the INSTALLED_APPS list.   [APP_NAME].apps.[APP_CONFIG_NAME]   To fin...

How to generate a random string with Python.

Photo by Pixabay. Hello everyone, welcome back to my blog. Today I will talk about how to generate a random string with Python. As a developer developing random strings is a vital task. I am working on a simple URL shortener app with Django. I will bring another article on that project as well. Before getting started, don't forget to subscribe to my blog using the subscribe button in the top-right corner. Importing modules. To get our job done, we have to import two important modules. They are built-in and no need to use PIP to install. random module. string module. here we use the random module to choose some random characters which are provided by the string module. you can use the following piece of code to import them. import random import string Writing the function To generate the random string we can create a function that returns the random string whenever we call. def create_string ( size = 10 , chars = string . ascii_lowercase + string . digits ):     return ...