Web Technologies
Web Technologies
import math
value = math.pow(num,n)
if(num%2==0):
print(num," is even!")
else:
print(num," is odd!")
4. WAP to print a “hello world” in a Django framework.
Ans: The steps to print “hello world” in Django framework are as following:
def index(request):
3. Now go to “urls.py” and link the “index” function in “views.py” to a URL pattern.
urlpatterns = [
path('',views.index,name="index")
mydb = msc.connect(host="localhost",user="root",password="1234")
myc = mydb.cursor()
myc.execute("show databases")
for x in myc:
print(x)
6. Write a program to manage the session.
1. Configure session settings in your Django project's settings.py file. You can specify options such as the session
engine and the session timeout. Here's a sample session configuration
# settings.py
# Enable sessions
SESSION_ENGINE = "django.contrib.sessions.backends.db"
SESSION_COOKIE_NAME = "my_session_cookie"
2. Create a view to set and retrieve session data. In your app's views.py, you can create a simple view that
sets and retrieves session data:
# views.py
def set_session(request):
request.session['username'] = 'john_doe'
def get_session(request):
# urls.py
2. Now in the root directory create a folder named “template” and inside that template folder create a html
file and add the given code.
<html>
<head>
<title></title>
</head>
<style>
form{
font-weight:bold;
width:auto;
border:2px solid black;
display:flex;
flex-direction:column;
justify-content:centre;
}
</style>
<body>
<form>
<p>Name</p><input type="text" />
<p>Password</p><input type="Password" />
<p>Email</p><input type="email" />
<p>Pincode</p><input type="number" />
<p>Phone Number: </p><input type="number" /><br><br>
<input type="submit" value="SUBMIT">
</form>
</body>
</html>
“ [os.path.join(BASE_DIR,”template”] “
5. In the url.py file map the URL pattern with the views method.
6.
from django.contrib import admin
from django.urls import path
from pythonlab import views
urlpatterns = [
path('',views.form,name="form")
]
6. Now execute the command to run the server.
4. Now map this “form” views method to blank url in “urls.py” file.
if flag ==-1:
11. Write a program to display "Welcome To Radiant" in the form when the "click" button is clicked.
The form title must be web development using python.
import tkinter as tk
def display_message():
label.config(text="Welcome To Radiant")
# Create the main window
root = tk.Tk()
root.title("Web Development using Python")
# Create a button and associate it with the display_message function
button = tk.Button(root, text="Click", command=display_message)
button.pack()
# Create a label to display the message
label = tk.Label(root, text="")
label.pack()
# Start the main event loop
root.mainloop()