My html page is blank, I tried the html in a live html editor and it works fine, but when I load the website up, it is blank, the redirects are working fine, but I see a blank page each time.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
text-align: center;
}
h1 {
color: #333;
}
.btn {
display: inline-block;
margin-top: 20px;
padding: 10px 20px;
background: #7289da;
color: #fff;
text-decoration: none;
border-radius: 5px;
}
.btn:hover {
background: #5a6ebc;
}
img {
border-radius: 50%;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Dashboard</h1>
<p>Welcome, {{ user.name }}</p>
<p>User ID: {{ user.id }}</p>
<img src="{{ user.avatar_url }}" alt="User Avatar">
<a href="{{ url_for('index') }}" class="btn">Logout</a>
</div>
</body>
</html>
My python file
import os
from flask import Flask, render_template, redirect, url_for, session
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
import discord
app = Flask(__name__)
app.secret_key = b"equinoxandme"
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true"
app.config["DISCORD_CLIENT_ID"] = "1240641615090024478"
app.config["DISCORD_CLIENT_SECRET"] = "CLIENTSECRETHER"
app.config["DISCORD_REDIRECT_URI"] = "http://127.0.0.1:5000/callback"
app.config["DISCORD_BOT_TOKEN"] = os.getenv("DISCORD_TOKEN")
discord = DiscordOAuth2Session(app)
@app.route("/login/")
def login():
return discord.create_session()
@app.route("/callback/")
def callback():
try:
discord.callback()
except Exception as e:
print(f"Error during callback: {e}")
return redirect(url_for("login"))
return redirect(url_for("dashboard"))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/dashboard/")
@requires_authorization
def dashboard():
user = discord.fetch_user()
return render_template("dashboard.html", user=user)
@app.errorhandler(Unauthorized)
def redirect_unauthorized(e):
return redirect(url_for("login"))
# Start the Flask application
app.run(debug=True)
I am using flask and discord.py.
I tried it in a html editor and it worked as expected but when I host it in my pc, it shows nothing but a blank page.
New contributor
ZephyrX3D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.