Following the docs :
Downloaded the default login template to a local file called ‘basic_login.html’
Served the app with
panel serve app.py --basic-auth my_password --cookie-secret my_super_safe_cookie_secret --basic-login-template basic_login.html
The login page loads, but once the username and password are provided, it returns a page with “405: Method Not Allowed”.
Any ideas on how to fix this? I was hoping to be able to use a custom login template.
Thanks.
1 Like
Marc
May 31, 2025, 12:05pm
2
Following the docs
script.py
import panel as pn
pn.extension(template="fast")
logout = pn.widgets.Button(name="Log out")
logout.js_on_click(code="""window.location.href = './logout'""")
pn.Column(f"Congrats `{pn.state.user}`. You got access!", logout).servable()
script.html
```html
Panel App | Login
* {
box-sizing: border-box;
margin:0;
padding: 0;
}
html {
height: 100%;
}
body {
font-family: 'Segoe UI', sans-serif;;
font-size: 1em;
height: 100%;
line-height: 1.6;
}
p {
padding-bottom: 5px;
}
.wrap {
align-items: center;
background: #fafafa;
display: flex;
height: 100%;
justify-content: center;
width: 100%;
}
.login-form {
background: #ffffff;
border: 1px solid #ddd;
margin: 0 auto;
padding: 2em;
width: 350px;
}
.form-input {
background: #fafafa;
border: 1px solid #eeeeee;
padding: 12px;
width: 100%;
}
.form-group {
margin-bottom: 1em;
}
.form-button {
background: #107bba;
border: 1px solid #ddd;
color: #ffffff;
padding: 10px;
text-transform: uppercase;
width: 100%;
}
.form-button:hover {
background: #0072b5;
}
.form-header {
text-align: center;
}
.form-footer {
text-align: center;
}
#logo {
margin-top: 2em;
}
#error-message {
text-align: center;
margin-bottom: 0em;
}
Login to access your application
Login
```
panel serve script.py --basic-auth my_password --cookie-secret my_super_safe_cookie_secret --basic-login-template script.html
Enter my_password
:
Click login button:
Hi Marc,
Thanks for your prompt response. Unfotunately, your ‘script.html’ has become mangled by the formatting. Is there a way to upload it as text?
Here’s script.html
<!-- Uses the template from https://github.com/bokeh/bokeh/tree/branch-3.2/examples/server/app/server_auth -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="en" name="docsearch:language">
<title>Panel App | Login</title>
<link rel="icon" type="image/x-icon" href="{{ PANEL_CDN }}images/favicon.ico">
<style>
* {
box-sizing: border-box;
margin:0;
padding: 0;
}
html {
height: 100%;
}
body {
font-family: 'Segoe UI', sans-serif;;
font-size: 1em;
height: 100%;
line-height: 1.6;
}
p {
padding-bottom: 5px;
}
.wrap {
align-items: center;
background: #fafafa;
display: flex;
height: 100%;
justify-content: center;
width: 100%;
}
.login-form {
background: #ffffff;
border: 1px solid #ddd;
margin: 0 auto;
padding: 2em;
width: 350px;
}
.form-input {
background: #fafafa;
border: 1px solid #eeeeee;
padding: 12px;
width: 100%;
}
.form-group {
margin-bottom: 1em;
}
.form-button {
background: #107bba;
border: 1px solid #ddd;
color: #ffffff;
padding: 10px;
text-transform: uppercase;
width: 100%;
}
.form-button:hover {
background: #0072b5;
}
.form-header {
text-align: center;
}
.form-footer {
text-align: center;
}
#logo {
margin-top: 2em;
}
#error-message {
text-align: center;
margin-bottom: 0em;
}
</style>
</head>
<body>
<div class="wrap">
<form class="login-form" action=".{{ login_endpoint }}" method="post">
<div class="form-header">
<h3><img id="logo" src="{{ PANEL_CDN }}images/logo_stacked.png" width="150" height="120"></h3>
<br>
<p> Login to access your application</p>
</div>
<div id="error-message" class="form-group">
<p style="color:rgb(255, 0, 0);font-weight:bold" class="errormessage">{{errormessage}}</p>
</div>
<p></p>
<!--Email Input-->
<div class="form-group">
<input name="username" type="text" class="form-input" autocapitalize="off" autocorrect="off" placeholder="username">
</div>
<!--Password Input-->
<div class="form-group">
<input name="password" type="password" class="form-input" placeholder="password">
</div>
<!--Login Button-->
<div class="form-group">
<button class="form-button" type="submit">Login</button>
</div>
<div><small></small></div>
</form>
</div>
</body>
</html>
Thanks. Turns out it was a problem with my panel version. The html error occurs with versions 1.4.1 and 1.4.5. Upgrading the version to 1.7.1 resolves the issue.