Comments (10)
for me it worked by calling saving session
v1.GET("/", func(c *gin.Context) {
session := sessions.Default(c)
flashes := session.Flashes()
session.Save() // <---- here it is!
c.HTML(http.StatusOK, "index.html", gin.H{
"flash": flashes,
})
})
from contrib.
The principle of flashes is that you read them once then delete them. It's what sessions.Flashes()
does but you need to save to remember the deletion.
from contrib.
+1
from contrib.
+1
from contrib.
I'm doing the same thing, and I see the flashes rendered by my template like this:
{{ range $f := .flash }}
<div class="alert alert-danger">{{ $f }}</div>
{{ end }}
However, if I see the flash message, then navigate to another page, the flash message persists until I navigate again.
What am I doing wrong?
from contrib.
maybe call session.Save() // <---- here it is!
? to save session with empty flashes
from contrib.
@vodolaz095 I'm already doing that quite liberally:
if u, _ := findUserByUsername(user.Username); u != nil {
msg := fmt.Sprintf("User already exists: %s", user.Username)
log.Println(msg)
session.AddFlash(msg)
err := session.Save() // <---- see, right there :)
if err != nil {
log.Println(err)
}
c.HTML(http.StatusOK, "signup.html", gin.H{
"flash": session.Flashes(),
"user": user,
})
return
}
from contrib.
Have you tried saving just before the return (therefore after session.Flashes()
)?
from contrib.
This seems to work, though I'm not sure why.
from contrib.
@clanstyles Does this solve your original problem as well?
from contrib.
Related Issues (20)
- [WIP] Move all middleware into separate repos on gin-contrib org HOT 8
- Package dependencies HOT 1
- Add the authorization middleware HOT 4
- Fix logrus import in ginrus (due to rename) HOT 3
- session Options is not working HOT 10
- Add the rollbar middleware HOT 2
- Duration for a valid JWT token
- JWT force token expiration HOT 1
- commonlog
- [SOLVED] gin-contrib has gone? HOT 6
- `time` attribute duplicated in logrus/ginrus entry HOT 3
- auto update
- expir
- What is the license? HOT 1
- how to get x-response-time and write it in the http header with gin? HOT 2
- [QUESTION] sessions: Session `Get` method HOT 2
- Broken link in the "About" section HOT 1
- add support for samesite options HOT 1
- Remove repository with stolen source code
- the github page were 404 not found
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contrib.