from django.db import models
from django.contrib.auth.models import User
class APIKey(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
key = models.CharField(max_length=64, unique=True)
from django.http import JsonResponse
from your_app.models import APIKey
def api_key_required(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
api_key = request.headers.get("X-API-Key")
if not api_key or not APIKey.objects.filter(key=api_key).exists():
return JsonResponse({"error": "Unauthorized"}, status=403)
return view_func(request, *args, **kwargs)
return _wrapped_view
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
@api_key_required
def my_api_view(request):
return JsonResponse({"message": "Success"})
kubectl run -it some_unique_name --image youre/image:tag --restart=Never --rm -- /bin/bash
Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n or \r\n\r\n) are considered a paragraph and wrapped in tags. One newline (\n or \r\n) is considered a linebreak and a
tag is appended. This method does not remove the newlines from the text.
You can pass any HTML attributes into html_options. These will be added to all created paragraphs.
Options
:sanitize - If false, does not sanitize text.
:wrapper_tag - String representing the wrapper tag, defaults to "p"
static string ToHtml(string text, bool sanitize = true, string? wrap = null)
{
var normalized = text.Replace("\r\n", "\n");
if (sanitize)
normalized = WebUtility.HtmlEncode(normalized);
var paragraphs = text.Split("\n\n")
.Select(paragraph =>
{
var lines = paragraph.Split("\n");
return string.Join("\n<br/>", lines);
});
var htmlText = string.Join("\n\n", paragraphs.Select(p => $"<p>\n{p}\n</p>"));
return wrap != null
? $"<{wrap}>\n{htmlText}\n</{wrap}>"
: htmlText;
}
yourapp --kill-that-fucking-idiot
. Или, если нужно к запущеному - так, как Александр Таратин написал