'Is it possible to add a feature to attach code-blocks to a post form?
I've been trying to find something about this for a while, but I don't know if its my wording but I can't seem to find anything about it.
Anyways... I'm working on a project for school, and basically it's a website that does many things, and one of those things is like a mini-stackoverflow thing but just for my school's community. So I have designed a form for the post using crispy forms however I can't seem to find any information on how to add the feature to write in code blocks to a form (just like we do here on Stack Overflow).
This is what the form looks like on code:
Template:
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Nueva Publicación</legend>
{{ form|crispy }}
</fieldset>
<div>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Crear Publicación</button>
</div>
</form>
Models
class Post(models.Model):
titulo = models.CharField(max_length=150)
contenido = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
imagen = models.ImageField(default='default.jpg', upload_to='blog_images')
def __str__(self):
return self.titulo
def get_absolute_url(self):
return reverse("post-detail", kwargs={"pk": self.pk})
Visually:
If you guys need anything else in order to help, please tell me and I will provide ASAP.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

