To pass a big text parameter through a URL in Django, you can use the GET method. Here's an example:

  1. In your views.py file, create a function to handle the request:
from django.shortcuts import render

def my_view(request):
    my_text = request.GET.get('my_text', '') # get the 'my_text' parameter from the URL
    return render(request, 'my_template.html', {'my_text': my_text})
  1. In your urls.py file, add a URL pattern for the view:
from django.urls import path
from . import views

urlpatterns = [
    path('my_view/', views.my_view, name='my_view'),
]
  1. In your template file (my_template.html), display the my_text variable:
<!DOCTYPE html>
<html>
<head>
    <title>My Template</title>
</head>
<body>
    <h1>My Text: {{ my_text }}</h1>
</body>
</html>
  1. To pass the big text parameter through the URL, simply append it to the URL as a query string:
http://localhost:8000/my_view/?my_text=This%20is%20a%20big%20text%20parameter.

Note that spaces in the big text parameter should be encoded as %20.

Django: Passing Large Text Parameters Through URLs

原文地址: https://www.cveoy.top/t/topic/mDgt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录