Here are the examples of the python api django.shortcuts.HttpResponse taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
529 Examples
3
Source : views.py
with GNU General Public License v3.0
from abhishek-ram
with GNU General Public License v3.0
from abhishek-ram
def get(self, request, *args, **kwargs):
"""Handle the GET call made to the AS2 server post endpoint."""
return HttpResponse(
_("To submit an AS2 message, you must POST the message to this URL")
)
def options(self, request, *args, **kwargs):
3
Source : views.py
with GNU General Public License v3.0
from abhishek-ram
with GNU General Public License v3.0
from abhishek-ram
def options(self, request, *args, **kwargs):
"""Handle the OPTIONS call made to the AS2 server post endpoint."""
response = HttpResponse()
response["allow"] = ",".join(["POST", "GET"])
return response
class SendAs2Message(FormView):
3
Source : views.py
with MIT License
from adarsh1021
with MIT License
from adarsh1021
def upload(request):
if request.method == 'POST':
data = request.POST["base64_img"]
format, imgstr = data.split(';base64,')
ext = '.'+format.split('/')[-1]
# print(ext)
directory = "STEPS/0"
filename = directory + ".jpg"
with open(filename, "wb") as fh:
fh.write(base64.b64decode(imgstr))
# clone.delay()
return HttpResponse("success")
return HttpResponse("fail")
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_smiles(request, smiles):
'''
Returns a png response for a target smiles
'''
from makeit.utilities.io.draw import MolsSmilesToImage, MakeBackgroundTransparent
isTransparent = request.GET.get('transparent', 'False')
response = HttpResponse(content_type='image/png')
if isTransparent.lower() in ['true', 't', 'yes', 'y', '1']:
MakeBackgroundTransparent(MolsSmilesToImage(str(smiles))).save(response, 'png', quality=70)
else:
MolsSmilesToImage(str(smiles)).save(response, 'png', quality=70)
return response
#@login_required
def draw_template(request, template):
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_template(request, template):
'''
Returns a png response for a reaction SMARTS template
'''
from makeit.utilities.io.draw import TransformStringToImage
response = HttpResponse(content_type='image/jpeg')
TransformStringToImage(str(template)).save(response, 'png', quality=70)
return response
# @login_required
def draw_reaction(request, smiles):
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_reaction(request, smiles):
'''
Returns a png response for a SMILES reaction string
'''
from makeit.utilities.io.draw import ReactionStringToImage
response = HttpResponse(content_type='image/jpeg')
ReactionStringToImage(str(smiles)).save(response, 'png', quality=70)
return response
def draw_mapped_reaction(request, smiles):
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_mapped_reaction(request, smiles):
'''
Returns a png response for a SMILES reaction string
'''
from makeit.utilities.io.draw import ReactionStringToImage
response = HttpResponse(content_type='image/jpeg')
print('in views', smiles)
ReactionStringToImage(str(smiles), strip=False).save(response, 'png', quality=70)
return response
def draw_highlighted_reaction(request, smiles):
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_highlighted_reaction(request, smiles):
'''
Returns a png response for a SMILES reaction string
'''
from makeit.utilities.io.draw import MappedReactionToHightlightImage
response = HttpResponse(content_type='image/jpeg')
print('in views', smiles)
MappedReactionToHightlightImage(str(smiles), highlightByReactant=True).save(response, 'png', quality=70)
return response
def draw_smiles_highlight(request, smiles, reacting_atoms, bonds='False'):
3
Source : draw.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def draw_fig(request, fig):
'''
Returns a png response for figure object
'''
response = HttpResponse(content_type='img/png')
canvas = FigureCanvas(fig)
canvas.print_png(response)
return response
3
Source : price.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def price_smiles(request, smiles):
response = HttpResponse(content_type = 'text/plain')
ppg = Pricer.lookup_smiles(smiles, alreadyCanonical=True)
if ppg:
response.write('${}/g'.format(ppg))
else:
response.write('cannot buy')
return response
@ajax_error_wrapper
3
Source : price.py
with Mozilla Public License 2.0
from ASKCOS
with Mozilla Public License 2.0
from ASKCOS
def price_xrn(request, xrn):
response = HttpResponse(content_type = 'text/plain')
ppg = Pricer.lookup_xrn(xrn)
if ppg:
response.write('${}/g'.format(ppg))
else:
response.write('cannot buy')
return response
3
Source : views.py
with GNU General Public License v3.0
from cc0411
with GNU General Public License v3.0
from cc0411
def post(request):
ret = {'status':True,'error':None}
try:
if request.POST.get('nid'):
ids = request.POST.get('nid',None)
models.Assets.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id',None)
idstring = ','.join(ids)
models.Assets.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status']= False
ret['error'] = '没有权限'
finally:
return HttpResponse(json.dumps(ret))
@login_required()
3
Source : views.py
with GNU General Public License v3.0
from cc0411
with GNU General Public License v3.0
from cc0411
def post(self, request):
image_form = UploadImageForm(request.POST, request.FILES, instance=request.user)
if image_form.is_valid():
image_form.save()
return HttpResponse(
'{"status":"success"}',
content_type='application/json')
else:
return HttpResponse(
'{"status":"fail"}',
content_type='application/json')
class UserDelView(LoginRequiredMixin,DeleteView):
3
Source : views.py
with GNU General Public License v3.0
from cc0411
with GNU General Public License v3.0
from cc0411
def post(self,request,second_menu_id):
form = PermissionForm(data=request.POST)
if form.is_valid():
second_menu_obj = Permission.objects.filter(id=second_menu_id).first()
if not second_menu_obj:
return HttpResponse('二级菜单不存在')
form.instance.pid = second_menu_obj
form.save()
return redirect(memory_reverse(request,'user:menu_list'))
class PermissionUpdateView(LoginRequiredMixin,UpdateView):
3
Source : views.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def get(self, request):
# return_url的回调地址
print('get...', request.data)
# 用户支付成功之后回到哪
return HttpResponse(" < h3>支付成功 < /h3> < a href='http://localhost:8080/Order' >查看我的账单 < /a>")
def post(self, request):
3
Source : consult_record.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def save(self, request, form, is_update, *args, **kwargs):
student_id = kwargs.get('student_id')
student_obj = models.Student.objects.filter(id=student_id).first()
if not student_obj:
return HttpResponse('非法操作')
tutor = student_obj.tutor
if not is_update:
form.instance.student = student_obj.account
form.instance.consultant = tutor
form.save()
def get_list_display(self, request, *args, **kwargs):
3
Source : homework_detail.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def download(self, request, pk, *args, **kwargs):
"""
下载学员的作业
:param request:
:param pk:
:param args:
:param kwargs:
:return:
"""
file = str(self.model_class.objects.filter(id=pk).first().file)
file_link = settings.BASE_FILE + file
return HttpResponse(' < a href="%s" download="%s">点我下载 < /a>' % (file_link, file))
list_display = [
3
Source : views.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def get(self, request):
user_id = 'Auth_'
gt = GeetestLib(pc_geetest_id, pc_geetest_key)
status = gt.pre_process(user_id)
# request.session[gt.GT_STATUS_SESSION_KEY] = status
# request.session["user_id"] = user_id
RedisConn.set(gt.GT_STATUS_SESSION_KEY, status)
RedisConn.set("user_id", user_id)
response_str = gt.get_response_str()
return HttpResponse(response_str)
def post(self, request):
3
Source : views.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def upload(request):
"""富文本编辑,图片在线显示"""
img = request.FILES.get('upload_img')
path = os.path.join(settings.MEDIA_ROOT, 'article_img', img.name)
f = open(path, 'wb')
for biner in img:
f.write(biner)
f.close()
responese = {
'error': 0,
'url': 'media/article_img/%s' % img.name
}
return HttpResponse(json.dumps(responese))
3
Source : role.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def role_edit(request, id):
obj = Role.objects.filter(id=id).first()
if not obj:
return HttpResponse('不存在该用户')
if request.method == 'GET':
form = RoleModelForm(instance=obj)
return render(request, 'rbac/change.html', {'form': form})
form = RoleModelForm(instance=obj, data=request.POST)
if form.is_valid():
form.save()
return redirect(reverse('rbac:role_list'))
return render(request, 'rbac/change.html', {'form': form})
def role_del(request, id):
3
Source : user.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def user_reset_password(request, id):
obj = User.objects.filter(id=id).first()
if not obj:
return HttpResponse('不存在该用户')
if request.method == 'GET':
form = ResetUserModelForm()
return render(request, 'rbac/change.html', {'form': form})
form = ResetUserModelForm(instance=obj, data=request.POST)
if form.is_valid():
form.save()
return redirect(reverse('rbac:user_list'))
return render(request, 'rbac/change.html', {'form': form})
def user_edit(request, id):
3
Source : user.py
with MIT License
from Eeyhan
with MIT License
from Eeyhan
def user_edit(request, id):
obj = User.objects.filter(id=id).first()
if not obj:
return HttpResponse('不存在该用户')
if request.method == 'GET':
form = UpdateUserModelForm(instance=obj)
return render(request, 'rbac/change.html', {'form': form})
form = UpdateUserModelForm(instance=obj, data=request.POST)
if form.is_valid():
form.save()
return redirect(reverse('rbac:user_list'))
return render(request, 'rbac/change.html', {'form': form})
def user_del(request, id):
3
Source : views.py
with Apache License 2.0
from FarjaalAhmad
with Apache License 2.0
from FarjaalAhmad
def data(request):
if request.method == 'POST' and request.POST['image']:
image = request.POST['image']
data = base64.b64decode(image)
image_name = datetime.datetime.now().strftime("%Y%b%d%H%M%S%f") + ".jpg"
image_path = os.getcwd() + "/uploads/" + image_name
with open(image_path, "wb") as f:
f.write(data)
input_path = os.getcwd() + "/uploads/" + image_name
output_path = os.getcwd() + "/uploads/" + image_name.split(".")[0] + "_processed.png"
remover.process(input_path, output_path)
image_path = "/uploads/" + image_name.split(".")[0] + "_processed.png"
return HttpResponse(request.get_host() + image_path)
3
Source : views.py
with GNU General Public License v3.0
from foonsun
with GNU General Public License v3.0
from foonsun
def post(self, request, **kwargs):
"""
When called with a post request, try and get 'promo' from
the post data and use it to reorder the page content blocks.
"""
data = dict(request.POST).get('promo')
self._save_page_order(data)
return HttpResponse(status=200)
def _save_page_order(self, data):
3
Source : views.py
with GNU General Public License v3.0
from foonsun
with GNU General Public License v3.0
from foonsun
def post(self, request, pk):
order = dict(request.POST).get('product')
self._save_page_order(order)
return HttpResponse(status=200)
def _save_page_order(self, order):
3
Source : middleware.py
with GNU General Public License v2.0
from getway
with GNU General Public License v2.0
from getway
def __call__(self, request):
if self.DEMO_MODE_ENABLED and request.method not in self.SAFE_METHOD \
and not self.SAFE_URL_PATTERN.match(request.path):
return HttpResponse("Demo mode, only safe request accepted", status=403)
else:
response = self.get_response(request)
return response
3
Source : user.py
with GNU General Public License v2.0
from getway
with GNU General Public License v2.0
from getway
def post(self, request, *args, **kwargs):
# print(request.POST)
form = forms.LDAPUserUpdateForm(request.POST)
if form.is_valid():
objectClass = form.cleaned_data['objectClass']
uid = form.cleaned_data['uid']
cn = form.cleaned_data['cn']
mail = form.cleaned_data['mail']
givenName = form.cleaned_data['givenName']
displayName = form.cleaned_data['displayName']
employeeNumber = form.cleaned_data['employeeNumber']
mobile = form.cleaned_data['mobile']
postalAddress = form.cleaned_data['postalAddress']
return HttpResponse(json.dumps(objectClass))
class LDAPUserListView(AdminUserRequiredMixin, TemplateView):
3
Source : user.py
with GNU General Public License v2.0
from getway
with GNU General Public License v2.0
from getway
def post(self, request):
try:
users_id = json.loads(request.body).get('users_id', [])
except ValueError:
return HttpResponse('Json object not valid', status=400)
spm = uuid.uuid4().hex
cache.set(spm, users_id, 300)
url = reverse('users:user-export') + '?spm=%s' % spm
return JsonResponse({'redirect': url})
class UserBulkImportView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
3
Source : user.py
with GNU General Public License v2.0
from getway
with GNU General Public License v2.0
from getway
def get(self, request, *args, **kwargs):
private, public = ssh_key_gen(username=request.user.username, hostname='jumpserver')
request.user.public_key = public
request.user.save()
response = HttpResponse(private, content_type='text/plain')
filename = "{0}-jumpserver.pem".format(request.user.username)
response['Content-Disposition'] = 'attachment; filename={}'.format(filename)
return response
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def dispatch(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
name = Names.objects.get(username=self.request.user)
project = AssetInfo.objects.get(id=pk).project
project_obj = AssetProject.objects.get(projects=project)
hasperm = name.has_perm('change_assetproject', project_obj)
if not hasperm:
return HttpResponse(status=500)
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def dispatch(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
name = Names.objects.get(username=self.request.user)
project = AssetInfo.objects.get(id=pk).project
project_obj = AssetProject.objects.get(projects=project)
hasperm = name.has_perm('read_assetproject', project_obj)
if not hasperm:
return HttpResponse(status=500)
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def dispatch(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
name = Names.objects.get(username=self.request.user)
project = AssetLoginUser.objects.get(id=pk).project
project_obj = AssetProject.objects.get(projects=project)
hasperm = name.has_perm('change_assetproject', project_obj)
if not hasperm:
return HttpResponse(status=500)
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def dispatch(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
name = Names.objects.get(username=self.request.user)
pro = AssetLoginUser.objects.get(id=pk).project
proj = AssetProject.objects.get(projects=pro)
hasperm = name.has_perm('read_assetproject', proj)
if not hasperm:
return HttpResponse(status=500)
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def dispatch(self, *args, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
name = Names.objects.get(username=self.request.user)
project_obj = AssetProject.objects.get(id=pk)
hasperm = name.has_perm('change_assetproject', project_obj)
if not hasperm:
return HttpResponse(status=500)
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
AssetBusiness.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
AssetBusiness.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class AssetBusinessUpdate(LoginRequiredMixin, UpdateView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
CrontabSchedule.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
CrontabSchedule.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class IntervalsListAll(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
IntervalSchedule.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
IntervalSchedule.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class PeriodicTasksListAll(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
PeriodicTask.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
PeriodicTask.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class PeriodicTaskReturnList(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
Names.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
Names.objects.extra(
where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class GroupListAll(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
Groups.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
Groups.objects.extra(
where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class GroupObjectListAll(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
GroupObjectPermission.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
GroupObjectPermission.objects.extra(
where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class GroupsObjectUpdate(LoginRequiredMixin, UpdateView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def taskstailstopperform(request):
"""
执行 tail_log stop 命令
"""
if request.method == "POST":
ret = {'status': True, 'error': None, }
name = request.user.username
os.environ["".format(name)] = "false"
return HttpResponse(json.dumps(ret))
class ToolsList(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
Tools.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
Tools.objects.extra(
where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
class ToolsExec(LoginRequiredMixin, ListView):
3
Source : views.py
with Apache License 2.0
from hequan2017
with Apache License 2.0
from hequan2017
def post(request):
ret = {'status': True, 'error': None, }
try:
if request.POST.get('nid'):
ids = request.POST.get('nid', None)
Variable.objects.get(id=ids).delete()
else:
ids = request.POST.getlist('id', None)
idstring = ','.join(ids)
Variable.objects.extra(where=['id IN (' + idstring + ')']).delete()
except Exception as e:
ret['status'] = False
ret['error'] = '删除请求错误,没有权限{}'.format(e)
finally:
return HttpResponse(json.dumps(ret))
3
Source : views.py
with MIT License
from hequan2017
with MIT License
from hequan2017
def post(self, request):
ret = {'status': True, 'error': None, }
nid = self.request.POST.get('nid', None)
self.model.objects.get(id=nid).delete()
return HttpResponse(json.dumps(ret))
# Ecs Api drf 中文文档 http://drf.jiuyou.info/#/drf/requests
class ApiEcsList(generics.ListCreateAPIView):
3
Source : views.py
with MIT License
from hequan2017
with MIT License
from hequan2017
def post(self, request):
token = (json.loads(request.body))['token']
obj = Token.objects.get(key=token).user
result = {
'name': obj.username,
'user_id': obj.id,
'access': list(obj.get_all_permissions()) + ['admin'] if obj.is_superuser else list(
obj.get_all_permissions()),
'token': token,
'avatar': 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
}
return HttpResponse(json.dumps(result))
class UserLogout(APIView):
3
Source : views.py
with MIT License
from hequan2017
with MIT License
from hequan2017
def post(self, request):
token = (json.loads(request.body))['token']
obj = Token.objects.get(key=token)
obj.delete()
result = {
"status": True
}
return HttpResponse(json.dumps(result))
class Menu(APIView):
3
Source : views.py
with Apache License 2.0
from huyuan1999
with Apache License 2.0
from huyuan1999
def upload_ssh_key(request):
if request.method == 'POST':
pkey = request.FILES.get('pkey')
ssh_key = pkey.read().decode('utf-8')
while True:
filename = unique()
ssh_key_path = os.path.join(TMP_DIR, filename)
if not os.path.isfile(ssh_key_path):
with open(ssh_key_path, 'w') as f:
f.write(ssh_key)
break
else:
continue
return HttpResponse(filename)
3
Source : views.py
with MIT License
from itdagene-ntnu
with MIT License
from itdagene-ntnu
def vcard(request, pk):
try:
if not request.user.is_staff:
person = (
User.objects.filter(Q(is_staff=True) | Q(id=request.user.id))
.filter(is_active=True)
.get(pk=pk)
)
else:
person = User.objects.filter(is_active=True).order_by("username").get(pk=pk)
except Exception:
raise Http404
output = vcard_string(person)
filename = slugify(person.get_full_name())
response = HttpResponse(output, content_type="text/x-vCard")
response["Content-Disposition"] = "attachment; filename=%s" % filename
return response
3
Source : views.py
with GNU General Public License v3.0
from jahyeonbeak
with GNU General Public License v3.0
from jahyeonbeak
def echo(request):
if not request.is_websocket():#判断是不是websocket连接
try:#如果是普通的http方法
message = request.GET['message']
return HttpResponse(message)
except:
return render(request, 'index.html')
else:
print ('open socket')
db_helper._set_request(request)
for message in request.websocket:
print(message)
#if request.websocket is None:
# break
#request.websocket.send('ttttttttttttt'.encode(encoding="utf-8"))
pass
#for message in request.websocket:
# request.websocket.send(message)#发送消息到客户端
See More Examples