Skip to content

Commit f62492e

Browse files
committed
Added middleware to allow 'is_ajax' method with recent django version
2 parents 416738b + 16f4931 commit f62492e

File tree

9 files changed

+57
-81
lines changed

9 files changed

+57
-81
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# Change Log
22

3+
## [1.0.1] 2023-06-02
4+
### Changes
5+
6+
- Update DEPS
7+
- Update Docker
8+
- Update Settings for `Django` (latest version)
9+
310
## [1.0.0] 2020-11-22
4-
### Initial Release
11+
### Changes
12+
13+
- STABLE Version
14+

Dockerfile

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
FROM python:3.6
1+
FROM python:3.9
22

3-
ENV FLASK_APP run.py
3+
# set environment variables
4+
ENV PYTHONDONTWRITEBYTECODE 1
5+
ENV PYTHONUNBUFFERED 1
46

5-
COPY manage.py gunicorn-cfg.py requirements.txt .env ./
6-
COPY app app
7-
COPY authentication authentication
8-
COPY core core
7+
COPY requirements.txt .
8+
# install python dependencies
9+
RUN pip install --upgrade pip
10+
RUN pip install --no-cache-dir -r requirements.txt
911

10-
RUN pip install -r requirements.txt
12+
COPY . .
1113

12-
RUN python manage.py makemigrations
14+
# running migrations
1315
RUN python manage.py migrate
1416

15-
EXPOSE 5005
17+
# gunicorn
1618
CMD ["gunicorn", "--config", "gunicorn-cfg.py", "core.wsgi"]

README.md

+3-54
Original file line numberDiff line numberDiff line change
@@ -157,63 +157,12 @@ $ cd django-datatables-sample
157157
> Start the app in Docker
158158
159159
```bash
160-
$ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d
160+
$ docker-compose up --build
161161
```
162162

163-
Visit `http://localhost:5005` in your browser. The app should be up & running.
163+
Visit `http://localhost:5085` in your browser. The app should be up & running.
164164

165165
<br />
166166

167-
### [Gunicorn](https://gunicorn.org/)
168167
---
169-
170-
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX.
171-
172-
> Install using pip
173-
174-
```bash
175-
$ pip install gunicorn
176-
```
177-
> Start the app using gunicorn binary
178-
179-
```bash
180-
$ gunicorn --bind=0.0.0.0:8001 core.wsgi:application
181-
Serving on http://localhost:8001
182-
```
183-
184-
Visit `http://localhost:8001` in your browser. The app should be up & running.
185-
186-
187-
<br />
188-
189-
### [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/)
190-
---
191-
192-
Waitress (Gunicorn equivalent for Windows) is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library.
193-
194-
> Install using pip
195-
196-
```bash
197-
$ pip install waitress
198-
```
199-
> Start the app using [waitress-serve](https://docs.pylonsproject.org/projects/waitress/en/stable/runner.html)
200-
201-
```bash
202-
$ waitress-serve --port=8001 core.wsgi:application
203-
Serving on http://localhost:8001
204-
```
205-
206-
Visit `http://localhost:8001` in your browser. The app should be up & running.
207-
208-
<br />
209-
210-
## Credits & Links
211-
212-
- [Django](https://www.djangoproject.com/) - The official website
213-
- [Boilerplate Code](https://appseed.us/boilerplate-code) - Index provided by **AppSeed**
214-
- [Boilerplate Code](https://github.com/app-generator/boilerplate-code) - Index published on Github
215-
216-
<br />
217-
218-
---
219-
[Django Datatables Sample](https://django-datatables-sample.appseed.us/) - Provided by **AppSeed** [Web App Generator](https://appseed.us/app-generator).
168+
[Django Datatables Sample](https://django-datatables-sample.appseed.us/) - Provided by [AppSeed](https://appseed.us).

authentication/forms.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ class LoginForm(forms.Form):
1212
widget=forms.TextInput(
1313
attrs={
1414
"placeholder" : "Username",
15-
"class": "form-control",
16-
"value": "test"
15+
"class": "form-control"
1716
}
1817
))
1918
password = forms.CharField(
2019
widget=forms.PasswordInput(
2120
attrs={
2221
"placeholder" : "Password",
23-
"class": "form-control",
24-
"value": "ApS12_ZZs8"
22+
"class": "form-control"
2523
}
2624
))
2725

core/settings.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
# SECURITY WARNING: keep the secret key used in production secret!
1919
SECRET_KEY = os.environ.get('SECRET_KEY')
2020
if not SECRET_KEY:
21-
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ))
21+
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
2222

2323
# SECURITY WARNING: don't run with debug turned on in production!
2424
DEBUG = os.getenv('DEBUG', False)
2525

26-
# load production server from .env
27-
ALLOWED_HOSTS = ['localhost', '127.0.0.1', os.getenv('SERVER', '127.0.0.1')]
26+
# HOSTs List
27+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
28+
29+
# Add here your deployment HOSTS
30+
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000', 'http://localhost:5085', 'http://127.0.0.1:8000', 'http://127.0.0.1:5085']
2831

2932
# Application definition
3033

core/templates/accounts/login.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h1 class="mb-0 h3">
2828
{% if msg %}
2929
{{ msg | safe }}
3030
{% else %}
31-
Use default credentials: test / ApS12_ZZs8
31+
Add your credentials
3232
{% endif %}
3333
</p>
3434
</div>
@@ -70,7 +70,7 @@ <h1 class="mb-0 h3">
7070
</div>
7171

7272
</div>
73-
<button type="submit" name="login" class="btn btn-block btn-primary">Sign in</button>
73+
<button type="submit" name="login" class="btn btn-block btn-primary">Sign IN</button>
7474
</form>
7575

7676
<div class="d-flex justify-content-center align-items-center mt-4">

core/templates/accounts/register.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ <h1 class="mb-0 h3">
3333
</p>
3434
</div>
3535

36+
{% if success %}
37+
38+
<a href="{% url 'login' %}" class="btn btn-block btn-primary">Sign IN</a>
39+
40+
{% else %}
41+
3642
<form method="post" action="">
3743

3844
{% csrf_token %}
@@ -95,8 +101,12 @@ <h1 class="mb-0 h3">
95101
</div>
96102

97103
</div>
98-
<button type="submit" name="register" class="btn btn-block btn-primary">Sign in</button>
104+
<button type="submit" name="register" class="btn btn-block btn-primary">Sign UP</button>
99105
</form>
106+
107+
{% endif %}
108+
109+
100110
<div class="d-flex justify-content-center align-items-center mt-4">
101111
<span class="font-weight-normal">
102112
&copy; <a href="https://themesberg.com" target="_blank">Themesberg</a>

docker-compose.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
version: '3'
1+
version: '3.8'
22
services:
33
appseed-app:
4+
container_name: appseed_app
45
restart: always
5-
env_file: .env
66
build: .
7-
ports:
8-
- "5005:5005"
97
networks:
108
- db_network
119
- web_network
1210
nginx:
11+
container_name: nginx
1312
restart: always
1413
image: "nginx:latest"
1514
ports:
16-
- "85:85"
15+
- "5085:5085"
1716
volumes:
1817
- ./nginx:/etc/nginx/conf.d
1918
networks:

nginx/appseed-app.conf

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
upstream webapp {
2+
server appseed_app:5005;
3+
}
4+
15
server {
2-
listen 85;
6+
listen 5085;
7+
server_name localhost;
38

49
location / {
5-
proxy_pass http://localhost:5005/;
10+
proxy_pass http://webapp;
611
proxy_set_header Host $host;
712
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
813
}

0 commit comments

Comments
 (0)