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

Update _default/index.html #888

Merged
merged 1 commit into from
Jul 7, 2024
Merged
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
30 changes: 20 additions & 10 deletions apps/_default/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ <h2 id="why">WHAT IS PY4WEB?</h2>
$ py4web run apps # start py4web
</code></pre>

Each subfolder of <tt>apps/</tt> with an <tt>__init__.py</tt> is its own app. One py4web can run multiple apps. You just copy the <tt>_scaffold</tt> app to make a new one.
Each subfolder of <tt>apps/</tt> with an <tt>__init__.py</tt> is its own app. One py4web can run multiple apps.
You just copy the <tt>_scaffold</tt> app to make a new one.

</div><div class="section">

Expand Down Expand Up @@ -89,7 +90,8 @@ <h2 id="why">WHAT IS PY4WEB?</h2>
</code></pre>

</div><div class="section">
py4web uses a request object from <a href="https://github.com/valq7711/ombott">ombott</a>, compatible with <a href="https://bottlepy.org/docs/dev/">bottlepy</a>
py4web uses a request object from <a href="https://github.com/valq7711/ombott">ombott</a>, compatible with
<a href="https://bottlepy.org/docs/dev/">bottlepy</a>

<pre class="language-python"><code>
# http://127.0.0.1:8000/myapp/index/?x=1
Expand All @@ -100,7 +102,7 @@ <h2 id="why">WHAT IS PY4WEB?</h2>
</code></pre>

</div><div class="section">
I can parse JSON from POST requests for example
It can parse JSON from POST requests for example

<pre class="language-python"><code>
# http://127.0.0.1:8000/myapp/index POST {x: 1}
Expand Down Expand Up @@ -129,7 +131,10 @@ <h2 id="why">WHAT IS PY4WEB?</h2>
</code></pre>

</div><div class="section">
We have a built-in session object which by default stores the session data, encrypted, in a cookie. Optionally it can be stored in db, redist, or other custom storage. Session is a fixture and it must be declared with <tt>@action.uses</tt>. Think of fixtures as per action (as opposed to per app) middleware.
We have a built-in session object which by default stores the session data, signed, in a cookie. Optionally it can be stored in db, redis,
or other custom storage. Session is a <a href="https://py4web.com/_documentation/static/en/chapter-06.html">fixture</a>
and it must be declared with <tt>@action.uses</tt>.
Think of fixtures as per action (as opposed to per app) middleware.

<pre class="language-python"><code>
@action("index")
Expand Down Expand Up @@ -163,15 +168,18 @@ <h1>x = [[=x]]</h1>
</code></pre>

</div><div class="section">
Py4web comes with a built-in <a href="https://py4web.com/_documentation/static/en/chapter-13.html">auth</a> object that generates all the pages required for user registration, login, email verification, retrieve and change password, edit profile, single sign on with OAuth2 and more. <tt>auth</tt> is also a fixture which exposed the current user to the action. Notice that fixtures have dependencies and by including <tt>auth</tt> its dependencies (db, session, flash).
Py4web comes with a built-in <a href="https://py4web.com/_documentation/static/en/chapter-13.html">auth</a> object that generates all the pages
required for user registration, login, email verification, retrieve and change password, edit profile, single sign on with OAuth2 and more.
<tt>auth</tt> is also a fixture which exposed the current user to the action. Notice that fixtures have dependencies, and by including
<tt>auth</tt> its dependencies (db, session, flash) are also included automatically.

<pre class="language-python"><code>
@action("index")
@action.uses("generic.html", auth)
def index():
user = auth.get_user()
if user:
message = "Hello {first_name}".format(**user)
message = f"Hello {user['first_name']}"
else:
message = "Hello, you are not logged in"
return {"message": message}
Expand All @@ -185,12 +193,14 @@ <h1>x = [[=x]]</h1>
@action.uses("generic.html", auth.user)
def index():
user = auth.get_user()
message = "Hello {first_name}".format(**user)
message = f"Hello {user['first_name']}"
return {"message": message}
</code></pre>

</div><div class="section">
More complex policies are possible using the built-in <a href="https://py4web.com/_documentation/static/en/chapter-07.html#tagging-records">tagging system</a> combined with <a href="https://py4web.com/_documentation/static/en/chapter-13.html#authorization-using-tags">auth</a>
More complex policies are possible using the built-in <a href="https://py4web.com/_documentation/static/en/chapter-07.html#tagging-records">tagging
system</a> combined with <a href="https://py4web.com/_documentation/static/en/chapter-13.html#authorization-using-tags">auth</a>.
<tt>Condition</tt> is another fixture, if False it raises a 404 error page by default.

<pre class="language-python"><code>
is_manager = Condition(lambda: "manager" in groups.get(auth.user_id))
Expand All @@ -199,7 +209,7 @@ <h1>x = [[=x]]</h1>
@action.uses("generic.html", auth.user, is_manager)
def index():
user = auth.get_user()
message = "Hello {first_name} (manager!)".format(**user)
message = f"Hello {user['first_name']} (manager!)"
return {"message": message}
</code></pre>

Expand All @@ -212,7 +222,7 @@ <h1>x = [[=x]]</h1>
db.define_table(
"thing",
Field("name", requires=IS_NOT_EMPTY()),
Field("image", "upload", download_url = lambda fn: URL(f"download/{fn}"))
Field("image", "upload", download_url = lambda fn: URL(f"download/{fn}")),
auth.signature)
</code></pre>

Expand Down
Loading