Debug School

rakesh kumar
rakesh kumar

Posted on

How to remove character from string in django

my string
['Kanoda is a small village in the Indian state of Rajasthan. It is located in the district of Udaipur and is known for its traditional art and culture. The village is home to many artisans who specialize in creating beautiful and intricate pieces of jewelry, pottery, and other handicrafts. The village is also known for its vibrant festivals and celebrations, which include the annual Kanoda Mela, a three-day fair that celebrates the local culture and traditions.']

here i have to remove opening bracket and closing bracket
Solution

my_string = recipe.about
Enter fullscreen mode Exit fullscreen mode

Image description

in view.py

def recipe_detail(request, id):           
    recipe = Recipe.objects.get(pk=id)
    field_value = recipe.nutrition
    my_string = recipe.about
    my_string = my_string[2:]
    my_string = my_string[:-2]

    return render(request, 'openai/dashboard.html', {'text': my_string})
Enter fullscreen mode Exit fullscreen mode

In template file

 {% if recipe %}         
          <h4 style="margin-top:10px">About:</h4>
          <p>{{ text }}</p>
          {% endif %}  
Enter fullscreen mode Exit fullscreen mode

Output

Image description

Top comments (0)