django-templates

STATIC(CSS AND JS) FILES ARE NOT WORKING AFTER UPLOADING WEBSITE ON HEROKU

倖福魔咒の 提交于 2021-01-29 07:24:31
问题 I have just uploaded my website on heroku, the css and javascript files works perfectly on localhost but doesn't work after deploying. I also made sure to run this command python manage.py collectstatic which i did both in the production and development environment but doesn't still solve the problem. I have included the necessary codes that would be useful, i have also included the images of both instances and my project directory Settings.py STATIC_URL = '/static/' STATIC_ROOT = os.path

Django + HTML: Why does my if condition in my template fail even thought I havent submitted interest?

心不动则不痛 提交于 2021-01-29 06:11:59
问题 Django + HTML: Why does my if condition in my template fail even thought I havent submitted interest? As you can see from my views.py i have already indicated that if you have submitted interest, you will get the message that you have submitted the interest, otherwise the button 'submit interest' will be shown. Why does it not work then? views.py def detail_blog_view(request, slug): context = {} #need to import a package get_object_or_404. return object or throw 404 blog_post = get_object_or

Django Add Field Error to Non-Model Form Field

牧云@^-^@ 提交于 2021-01-29 05:50:44
问题 Can anyone help me understand how to properly send a field error back to a non-model form field in django that is not using the standard django form validation process? Rendering the form again with error and user data still entered for correction and resubmission? Example html for a simple username field that is validated on the model level: <!--form--> <form id="profile" class="small" method="POST" action="{% url 'profile' %}"> {% csrf_token %} <!--Username--> <label for="username">Username

Render different date format depending on time that passed - either |timesince or |date

自作多情 提交于 2021-01-29 05:41:48
问题 Good morning. What I would like to achive is that when user posted sooner than 24h from now, I would like to have for example: Posted: 4h ago , but when it's more than 24h, it would be nice to have: Posted: November 10. First approach is doable by using: {{ post.date_posted|date:"F d, Y" }} , second one: {{ post.date_posted|timesince }} , but is there a way to "mix" them? Is is possible in Django? 回答1: I wrote my own time_utils.py in an app called custom_utils like below based on stack

Correct if/else statement syntax for django templates

有些话、适合烂在心里 提交于 2021-01-29 04:49:46
问题 I have a dating app and I need to create a link that is underneath each profile that a user matches on. Then, that link should pass their user id into the template so that messages are only displayed between the current user and that particular user based on the user id. I am having trouble here with the syntax of if/else statements within the Django template. How would I go about doing this? **base.html/href messages link ** <li class="nav-item"> <a class="nav-link" href="{% url 'dating_app

Django - extend date template filter

眉间皱痕 提交于 2021-01-29 04:14:06
问题 I am wondering if I can just define a variable like LONG_DATETIME_FORMAT = 'D d F Y H:i' in my settings and use it in template like: {{ my_date|date:"LONG_DATETIME_FORMAT" }} ? Can this be done without overwritting default date filter? Or should I write custom filter? 回答1: From the docs The format passed can be one of the predefined ones DATE_FORMAT , DATETIME_FORMAT , SHORT_DATE_FORMAT or SHORT_DATETIME_FORMAT , or a custom format that uses the format specifiers shown in the table above.

Sum of objects' prices in Django template

自闭症网瘾萝莉.ら 提交于 2021-01-28 08:18:46
问题 I would like to compute the total of a shopping cart in my template: This is my template with a table of products. I tried to use a Generator expression in my cart method but it doesn't work. Any thoughts? cart.html <table> {% if not cart_list %} {{ "The cart is empty" }} {% else %} <tr> <th>Name</th> <th>Price</th> </tr> {% for product in cart_list %} <tr> <td>{{ product.name }}</td> <td>${{ product.price }}</td> </tr> {% endfor %} <tr> <td>{{ Total }}</td> <td>{{ total_prices }}</td> </tr>

How can I automatically add the blogpost author into the member list?

試著忘記壹切 提交于 2021-01-28 08:00:43
问题 Everytime a blogpost is added, a memberlist will be generated. How do I automatically make it such that the author of the post will be included in the member list? I have added the create blog view models.py class BlogPost(models.Model): chief_title = models.CharField(max_length=50, null=False, blank=False, unique=True) body = models.TextField(max_length=5000, null=False, blank=False) members = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name="members") author =

How does Django's extends work?

别等时光非礼了梦想. 提交于 2021-01-28 07:11:27
问题 I have my index.html file in /templates directory and I have another index.html located in /templates/hello . I've created a file named templates.html in /templates/hello and it should extend index.html. Can I make template.html extends both index.html files (from both directories) using {% extends index.html %} tag in it? Thanks. 回答1: You cannot extend from multiple django templates.. it's a single line inheritance. If you want /templates/index.html to be your base index template, and

if comment.name == user not working correctly

强颜欢笑 提交于 2021-01-28 04:18:58
问题 I want users to be able to delete comments they have written. Unfortunately though I can not get the if statement to work. {% if comment.name == user %} <a href="{% url 'delete_own_comment' comment.id %}">delete this comment-</a> {% endif %} So I could see the value of user and comment.name I included the below code. This was for testing purposes and would not be included in the sites final design. <h3 class="article-content">{{ user }}</h3> <p class="article-content">{{ comment.name }}</p> I