diff --git a/features/csrf.md b/features/csrf.md index 3e4cbc3..774ace1 100644 --- a/features/csrf.md +++ b/features/csrf.md @@ -38,6 +38,11 @@ You can get also get the token that is generated. This is useful for JS frontend

Token: {{ csrf_token }}

``` +{% hint style="info" %} +If you encounter an 'Invalid CSRF Token' error while running the development server, ensure that the domains in your .env file and config/application.py match the domain used by the development server (e.g., both should use either 127.0.0.1 or localhost). +{% endhint %} + + ## AJAX / Vue / Axios For ajax calls, the best way to pass CSRF tokens is by setting the token inside a parent template inside a `meta` tag like this: diff --git a/features/validation.md b/features/validation.md index ab390a8..87d4f7c 100644 --- a/features/validation.md +++ b/features/validation.md @@ -64,11 +64,11 @@ If you want to handle errors in views specifically you will need to add the `Sha route middlewares. `errors` will be injected to views as a [MessageBag](#message-bag) instance allowing to handle errors easily: ```html -@if errors.any(): +@if bag().any():
@@ -81,22 +81,22 @@ route middlewares. `errors` will be injected to views as a [MessageBag](#message
- @if errors.has('name') - {{ errors.get('name')[0] }} + @if bag().has('name') + {{ bag().get('name')[0] }} @endif
- @if errors.has('email') - {{ errors.get('email')[0] }} + @if bag().has('email') + {{ bag().get('email')[0] }} @endif
- @if errors.has('message') - {{ errors.get('message')[0] }} + @if bag().has('message') + {{ bag().get('message')[0] }} @endif
@@ -448,7 +448,7 @@ def show(self, request: Request): You can easily get all errors using the `all()` method: ```python -errors.all() +bag().all() """ { 'email': ['Your email is required'], @@ -460,7 +460,7 @@ errors.all() ## Checking for any errors ```python -errors.any() #== True +bag().any() #== True ``` ## Checking if the bag is Empty @@ -468,26 +468,26 @@ errors.any() #== True This is just the opposite of the `any()` method. ```python -errors.empty() #== False +bag().empty() #== False ``` ## Checking For a Specific Error ```python -errors.has('email') #== True +bag().has('email') #== True ``` ## Getting the first Key: ```python -errors.all() +bag().all() """ { 'email': ['Your email is required'], 'name': ['Your name is required'] } """ -errors.first() +bag().first() """ { 'email': ['Your email is required'] @@ -498,13 +498,13 @@ errors.first() ## Getting the Number of Errors: ```python -errors.count() #== 2 +bag().count() #== 2 ``` ## Converting to JSON ```python -errors.json() +bag().json() """ '{"email": ["Your email is required"],"name": ["Your name is required"]}' """ @@ -513,13 +513,13 @@ errors.json() ## Get the Amount of Messages: ```python -errors.amount('email') #== 1 +bag().amount('email') #== 1 ``` ## Get the Messages: ```python -errors.get('email') +bag().get('email') """ ['Your email is required'] """ @@ -528,7 +528,7 @@ errors.get('email') ## Get the Errors ```python -errors.errors() +bag().errors() """ ['email', 'name'] """ @@ -537,7 +537,7 @@ errors.errors() ## Get all the Messages: ```python -errors.messages() +bag().messages() """ ['Your email is required', 'Your name is required'] """ @@ -548,7 +548,7 @@ errors.messages() You can also merge an existing dictionary into the bag with the errors: ```python -errors.merge({'key': 'value'}) +bag().merge({'key': 'value'}) ``` # Nested Validations