Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of property having access to self.request #653

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading