Skip to content

Commit

Permalink
Add example of property having access to self.request. #650
Browse files Browse the repository at this point in the history
  • Loading branch information
adamghill committed Feb 11, 2024
1 parent 7097b63 commit f229007
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions example/unicorn/components/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ class HelloWorldView(UnicornView):
def set_name(self):
self.name = "set_name method called"
return "set_name called at " + now().strftime("%H:%M:%S.%f")

@property
def user(self):
return self.request.user

class Meta:
javascript_exclude = (
"user",
)
5 changes: 5 additions & 0 deletions example/unicorn/templates/unicorn/hello-world-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<label></label>
<input unicorn:model="name" type="text" id="name" unicorn:key="key1">

<div>
User: {{ user }}
</div>
<br />

Hello, {{ name|default:'World' }}!

<div>
Expand Down

0 comments on commit f229007

Please sign in to comment.