test2023h5's picture
Upload 180 files
d95db82 verified
raw
history blame
2.1 kB
'''
title: session
'''
import simplestart as ss
ss.md("## ss.session - reactive session variables")
ss.md("By modifying the session variable, the view can be automatically re-rendered")
ss.space()
ss.md('''
---
#### πŸ”… Example 1 - Basic
''')
#in this page
ss.session["count"] = 100
mytext = ss.text("The couns is @count")
def change_count():
ss.session.count += 1
ss.button("Add Count", onclick=change_count)
ss.write('''
---
#### πŸ”Ž Code
''')
ss.md('''
```python
import simplestart as ss
ss.session["count"] = 100
mytext = ss.text("The couns is @count")
def change_count():
ss.session.count += 1
ss.button("Add Count", onclick=change_count)
```
''')
ss.space()
ss.md('''
---
#### πŸ”… Example 2 - Dict
''')
student = {
"name":"Sam",
"age":18,
"gender":"Male",
"favorite": "Sport, movie"
}
ss.session.data = student
ss.markdown('''
### Student Info
**Name:** @data.name
**Age:** @data.age
**Gender:** @data.gender
**Favorite:** @data.favorite
''')
def change_student(event):
student = {
"name":"Jane",
"age":17,
"gender":"Female",
"favorite": "Music, painting"
}
ss.session.data = student
def change_info(event):
ss.session.data["name"] = "Sally"
ss.button("Change Student", onclick = change_student)
ss.button("Change Info", onclick = change_info)
ss.write('''
---
#### πŸ”Ž Code
''')
ss.md('''
```python
import simplestart as ss
student = {
"name":"Sam",
"age":18,
"gender":"Male",
"favorite": "Sport, movie"
}
ss.session.data = student
ss.markdown(\'''
### Student Info
**Name:** \@data.name
**Age:** \@data.age
**Gender:** \@data.gender
**Favorite:** \@data.favorite
\''')
def change_student(event):
student = {
"name":"Jane",
"age":17,
"gender":"Female",
"image":"",
"favorite": "Music, painting"
}
ss.session.data = student
def change_info(event):
ss.session.data["name"] = "Sally"
ss.button("Change Student", onclick = change_student)
ss.button("Change Info", onclick = change_info)
```
''')