Welcome to Webmatrices Community

Welcome to Webmatrices Community

Our forum is here to help you fix your digital issues related to SEO, Digital Marketing, NFT development, Google Adsense, Blogging and more.

codie

Share your Django story, here's mine

Hey Devs.I started learning Django in COVID times. I was on my grade 12th ATM. I was into content writing and stuff. I had a site, and there was a tool named "Adsense Eligibility Checker" in my site, where user could fill the form, submit their site, and I'd check if there site is eligible or not. The requests were a lot, and task was tedious.I wanted to build something where my presence would not be required. So, I started searching for ways to make a tool/webapp. I was already into learning Python, so maybe fate wanted or something, I got to know about Django.I started learning it. It took me three weeks to nicely learn and 2-3 weeks to develop that tool. I was super happy, wanted to deploy on my cpanel-shared-hosting based server, I had to suffer a lot at that time. But does tons of searches, I deployed it. It got popular, I attached Google Ads on that platform, made a little good money, travelled to places in Nepal.My father's friend used to do Fiverr in Poland, and she suggested me to do so. I had some old Fiverr gigs added, but removed them (were primarily for Photoshop editing). Add a gig, "I'll deploy Django on cPanel", after 2 days of adding that gig, got an order from a Morroco-ian guy. Delivered it. And my journey boosted.I kept doing indie dev and freelancing. After 2 years, my revenue were not doing so well. Had to apply for a job, got the job, worked there for 5 and a half months, and US-based company named "Blogstorm.AI" offered me a job with comparatively good salary, started working there. It's been 1 and a half years working on blogstorm.Now, I am doing full-time job, indie dev and open source. There's a Django rest API framework, that I am working, called Djapy.IO . The journey is going good. I have migrated all my platforms code to Djapy.I hope to see some new guys in there. Life is good man, so is Django. Have a great day. For suggestions, believe on process.

Zaeemusmani replied a month ago
Noce good lovly
Published a month ago
3 likes 1466 watched 3 commented
codie

Django reCaptcha v3 – Install reCaptcha in Django site

Django Recaptcha v3 will be installed in your Django website soon, just follow my instructions. We will be using Google Recaptcha version 3 ( I am not a robot ) and a Python library django-recaptcha for this task.This is a repost of an old blog of ours.How to install, deploy or integrate Django recaptcha v3?Django recaptcha v3 installationFirst, install django-recaptcha in your virtual workspace.Visit the GitHub Repo of this task/project to get all the source codes.Install and configure django-recaptcha libpip install django-recaptchaNow, add captcha in the INSTALLED_APPS section in your settings.pycaptchaMust be similar to this:INSTALLED_APPS = [ 'captcha', # add this code 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', "your_app_name", # app name ]Recaptcha keys configurationAdd RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY at the last lines of your settings.pyRECAPTCHA_PUBLIC_KEY = 'MyRecaptchaKey123' RECAPTCHA_PRIVATE_KEY = 'MyRecaptchaPrivateKey456'Here, RECAPTCHA_PUBLIC_KEY means SITE KEY and RECAPTCHA_PRIVATE_KEY means SECRET KEY.Now, go to Google reCAPTCHA admin panel and register your site for reCAPTCHA and use those data in the upper code.Cpatcha Form configurationNow, create a file named my_captcha.py and inside it you need to write the following Python codes:from django import forms from captcha.fields import ReCaptchaField class FormWithCaptcha(forms.Form): captcha = ReCaptchaField()Django views configurationWrite a context with "captcha" variable name that with render the form we have coded in FormWithCaptcha which is inside the my_captcha.py .from django.shortcuts import render from .my_captcha import FormWithCaptcha # Create your views here. def home(request): context = { "captcha": FormWithCaptcha, } return render(request, "home.html", context)Rendering recaptcha v3Now, we are rendering recaptcha using the Jinja template method. Use {{captcha}} for rendering the captcha form.For now, have a look here:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <forms> {{captcha}} </forms> </body> </html>Getting data from recaptcha formTo get data from django recaptcha, you need to use g-recaptcha-response.get_recaptcha = request.POST.get("g-recaptcha-response")This will return true if the checkbox is checked, else false.

codie replied a month ago
You might also wanna check this video:https://youtu.be/8GNc4Pz4is4
Published a month ago
0 likes 413 watched 1 commented
codie

Activate.ps1 cannot be loaded because running scripts is disabled on this system

[REPOST] I am a noob at Python in Windows. I am getting env\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system. The issue in my Windows machine while activating the virtual environment. Can somebody help me, I am on my Visual Studio CODE.PS C:\Users\USER\Projects\content_idea_gen> env/Scripts/activate env/Scripts/activate : File C:\Users\USER\Projects\content_idea_gen\env\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + env/Scripts/activate + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

pramod replied a month ago
@codie Here's the solution. It’s the issue from your VSCODE.Open VSCODEPress F1, and type Preferences: Open Settings (JSON) and click on it. i.e Simply open settings.jsonGo to the bottom of settings.jsonAdd this line at the end of your visual studio code: "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]Your bottom settings.json should look like this..…. “explorer.confirmDelete”: false, “terminal.integrated.shell.windows”: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”, “terminal.integrated.shellArgs.windows”: [“-ExecutionPolicy”, “Bypass”] }
Published a month ago
0 likes 402 watched 1 commented
codie

How to deploy SvelteKit in VPS, AWS EC2 or Lightsail?

Deploying SvelteKit can be a tricky job, especially when you're doing it for the first time, unlike me. But, after a few deployments, you get used to with it. So, today, I am guiding you through it, and giving you exact ways to deploy and run your SvelteKit in the server.Also, will be talking about something that I personally developed, called svelte-deploy command.SvelteKit configurationFirst of all, you need a module to be installed in your sveltekit project, @sveltejs/adapter-node;npm install @sveltejs/adapter-nodeNow, you have to configure your svelte.config.js, by adding replacing that upper module with @sveltejs/adapter-auto;import adapter from '@sveltejs/adapter-node'; // ^ // replace @sveltejs/adapter-auto | const config = { preprocess: [ vitePreprocess(), preprocess({ postcss: true }) ], ...Now, your SvelteKit setup is almost done.Server setupIf you have installed git in your Lightsail server then what you have to do is, clone your repo to a specific folder.Creating a service setupNow, we need to create a service setup /etc/systemd/system/<your_svelte_service_name>.service:[Unit] Description=SvelteApp After=network.target [Service] User=root Group=www-data WorkingDirectory=/home/ubuntu/svelte-apps/<path-to-your-app> ExecStart=/home/ubuntu/.nvm/versions/node/v19.8.0/bin/node /home/ubuntu/svelte-apps/<path-to-your-app>/build/index.js Environment=PORT=3099 ORIGIN=https://yoursite.com [Install] WantedBy=multi-user.targetMake sure you have installed NodeJs, suggested to installed it using nvm. You can see learn about installing nvm here.And to checkout the path of your current running node, use whereis node, and paste your preferred node to ExecStart=path_to_node path_to_index.jsNginx Setupupstream sveltekit-frontend { server localhost:3099; } server { listen 80; listen [::]:80; set $app_dir "/home/ubuntu/svelte-apps/<path-to-your-app>"; # not required server_name yoursite.com; location / { proxy_pass http://sveltekit-frontend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }Now, run;sudo nginx -tIf result is:nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successfulIt's usually good, and you're ready to go. (if not, ask below, happy to help)Restart the servicesNow, restart the nginx and the created services:sudo systemctl enable <your_svelte_service_name>.service; sudo systemctl start <your_svelte_service_name>.service; sudo systemctl restart nginx.service;Done, now your site is up and running. Lemme know if you need help.Have a good day 😊

Published a month ago
3 likes 509 watched 0 commented
aryangupta001

I know my code is correct. But I want know that is my code completing all the demands of the qn.

Q2: Let A[n] be an array of n distinct integers. If i < j and A[i] > A[j], then the pair (i, j)is called an inversion of A. Write a C/C++ program that determines the number ofinversions in any permutation on n elements in O(n lg n) worst-case time.(Hint: Modify merge sort)Example: A = {4, 1, 3, 2} output is 4program:-#include<stdio.h> int total_inversions(int arr[], int n, int count); int main(){ int arr[] = {4, 1, 3, 2}; int n = sizeof(arr) / sizeof(arr[0]); int count = 0; count = total_inversions(arr, n , count); printf("%d", count); return 0; } int total_inversions(int arr[], int n, int count){ for(int i = 0; i < n-1; i++){ for(int j = i+1; j < n; j++){ if (arr[i] > arr[j]){ count++; } } } return count; }

somesh replied 2 months ago
Hey buddy!As you well know, the program you've suggested here is great, reliable but there's a certain hitch. It runs with a time complexity of O(n^2). This might not seem like a big deal but when you're dealing with huge arrays with a large number of elements, it may cause performance issues. The challenge here is finding the number of inversions in a permutation on n elements, but the trick is doing it within O(nlogn) worst-case time. A smart modification of the merge sort algorithm can be a real game changer here, and lucky for you, I tweaked it to our benefit here: #include<stdio.h> int merge(int arr[], int temp[], int left, int mid, int right); int _mergeSort(int arr[], int temp[], int left, int right); int inversionCount(int arr[], int n) { int temp[n]; return _mergeSort(arr, temp, 0, n - 1); } int _mergeSort(int arr[], int temp[], int left, int right) { int mid, inv_count = 0; if (right > left) { mid = (right + left)/2; inv_count = _mergeSort(arr, temp, left, mid); inv_count += _mergeSort(arr, temp, mid+1, right); inv_count += merge(arr, temp, left, mid+1, right); } return inv_count; } int merge(int arr[], int temp[], int left, int mid, int right) { int i, j, k; int inv_count = 0; i = left; j = mid; k = left; while ((i <= mid - 1) && (j <= right)) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = arr[j++]; inv_count = inv_count + (mid - i); } } while (i <= mid - 1) temp[k++] = arr[i++]; while (j <= right) temp[k++] = arr[j++]; for (i=left; i <= right; i++) arr[i] = temp[i]; return inv_count; } int main(int argv, char **args) { int arr[] = {4, 1, 3, 2}; printf("Number of inversions are %d \n", inversionCount(arr, sizeof(arr)/sizeof(arr[0]))); return 0; } As you asked, this piece of code will help you get the inversion count in an array and that too in O(nlogn) time complexity, thanks to merge sort.And before I close the lid on this one, I hope you are doing alright handling the pointers and recursion here. The inversion counting part is the only trick in this pudding. Remember, for every i in the first array, if j is an element in the second array, all elements after i in the first subarray and j in the second subarray will form valid inversions. So simply add up (mid – i) inversions for all such valid i and j!This should help you out. Let me know if you need me to break it down more.Happy Coding!
Published 2 months ago
0 likes 397 watched 1 commented
tej

I made my own simple web framework in Rust

I tried to create a simple embed HTTP server in Rust using Actix Web for the Desktop Tauri app. However, I found a lot of problems and unable to perform a simple file upload operation and have Websocket without extra dependencies. None of the stackoverflow solution worked for me.May be I am a Django Guy and found difficult to use Actix Web which may be my skill issue. So I thought to create my own web framework in Rust for embed projects.Here's github link: https://github.com/tejmagar/rusty-web/It is same like a Django's functional approach.use rusty_web::paths::{Path, Paths}; use rusty_web::request::Request; use rusty_web::response::Response; use rusty_web::server::run_server; fn home(request: Request, mut response: Response) { response.html(200, "Home Page".to_string()).send(); } fn about(request: Request, mut response: Response) { response.html(200, "About Us".to_string()).send(); } fn main() { let paths: Paths = vec![ Path::new("/".to_string(), home), Path::new("/about/".to_string(), about), ]; run_server("0.0.0.0:8080", paths); }I will be using this for my personal projects. Leave your suggestions to make this project better.

codie replied 2 months ago
Use struct.struct XYZStruct { var_1: String var_2: String var_3: AnotherStruct } struct AnotherStruct {}and something like this:fn about(request: Request, mut response: Response) { response.json(Status::Ok, XYZStruct::new(...)).send(); }
Published 2 months ago
1 likes 894 watched 4 commented