Django
- 17 ответов
- 0 вопросов
16
Вклад в тег
server {
listen 80 default_server;
listen [::]:80 default_server;
return 444;
}
server {
listen 80;
listen [::]:80;
server_name vashdomain.com;
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location / {
proxy_pass http://127.0.0.1:4567;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}
}
@contextmanager
def mongo_connection():
server = SSHTunnelForwarder(
'192.168.20.10',
ssh_username='username',
ssh_password='password',
remote_bind_address=('127.0.0.1', 27017))
server.start()
yield server
server.stop()
with mongo_connection() as server:
client = MongoClient('127.0.0.1', server.local_bind_port)
...
from rest_framework.authentication import SessionAuthentication
class CsrfExemptSessionAuthentication(SessionAuthentication):
def enforce_csrf(self, request):
return None
class AddingSomething(GenericAPIView):
permission_classes = (permissions.AllowAny, )
serializer_class = AddSomethingSerializer
authentication_classes = (CsrfExemptSessionAuthentication,)
queryset = None
def post(self, request, **kwargs):
# .. Some magic ..
return HttpResponseRedirect(redirect_to=reverse('something_added'))