Django: using variables as array indices?

Issue I am trying to create a template that will put items in a table. Controller: items = Item.all().order(‘name’).fetch(10) template_values = {‘items’: items, ‘headers’: [‘Name’, ‘Price’, ‘Quantity’]} render(‘Views/table.html’, self, template_values) Template: <table> <tr> {% for header in headers %} <th>{{header}}</th>

Continue reading

No reverse match. Ideas how to fix?

Issue Can anyone figure out why I’m getting a no reverse match error here: urls.py: urlpatterns = [ path(”, views.ReservationsFormView.as_view(), name=’reservations’), path(‘edit/<slug:pk>/’, EditReservationView.as_view(), name="edit_reservation"), path(‘reservation_complete/’, ReservationCompleteView.as_view(), name="reservation_complete"), path(‘reservations_account/’, ReservationAccountView.as_view(), name="reservations_account"), path(‘delete/<slug:pk>/’, DeleteReservationView.as_view(), name="delete_reservation"), ] It’s only happening, so far, on

Continue reading

How to add angular to django 1.6 temlate

Issue I have such template in django: <!DOCTYPE html > <html ng-app> <head> {% load staticfiles %} <link rel=”Stylesheet” type=”text/css” href=”{% static “style.css” %}” /> <script src=”ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.js”></script> </head> <body> <p> red </p> <input type=”text” ng-model=”name”> <h2> Hello {{ name }}

Continue reading

Django – Rating on Multiple Criteria: Model Formset?

Issue I have a content that I’d like to rate on multiple criteria. Imagine this kind of model: class Content(models.Model): name = models.CharField(max_length=50) class Criteria(models.Model): name = models.CharField(max_length=50) content = models.ForeignKey(Content) class ContRate(models.Model): user = models.ForeignKey(User, help_text=”Who rated ?”) crit

Continue reading

Django rating system

Issue I am trying to implement a rating system on a Django website. I have done my rating with just one star (booleanfield) false/true : <!– Favorite Album –> <a href=”{% url ‘music:favorite_album’ album.id %}” class=”btn btn-default btn-sm btn-favorite” role=”button”>

Continue reading

Django update the user's rate

Issue im trying to implement rate system where user can rate (for example such person) only once, but he can change his rate. class Rate(models.Model): class Meta: unique_together = ((‘sender’, ‘person’),) choice = models.IntegerField(null=False, blank=False, choices=RATE_CHOICES) sender = models.ForeignKey(User, on_delete=models.CASCADE)

Continue reading

AngularJS router does not load page served at `templateURL`

Issue This is my HTML page (which gets served when accessing the path /): <form ng-submit=”ctrl.loginUser()” name=”myLoginForm”> <div class=”form-group”> <label>Username</label> <input type=”text” name=”uname” class=”form-control” ng-model=”ctrl.loginuser.username” required> </div> <div class=”form-group”> <label>Password</label> <input type=”password” name=”pwd” class=”form-control” ng-model=”ctrl.loginuser.password” required> </div> <input type=”submit” value=”Login”>

Continue reading

File name repeating in nginx

Issue I’m trying to setup django project to work with gunicorn and nginx server. With DEBUG=FALSE. I see in nginx log that static word is repeated twice thus changing the path. # settings.py """ Django settings for cognizance project. Generated

Continue reading

While trying to reverse a url in django template html file, exception 'NoReverseMatch' occurs. I included the additional parameter in views function

Issue def entry(request, name): content = util.get_entry(name.strip()) if content == None: content = "## Page was not found" content = markdown(content) return render(request, "encyclopedia/entry.html", {‘content’: content, ‘title’: name}) def edit(request,title): content = util.get_entry(title.strip()) if content == None: return render(request, "encyclopedia/edit.html",

Continue reading

On Raw HTML, website looks as I intend it. But on Django, there is some blank space created during the for loop

Issue <div id="Project" class="bg-white fnt-white brdr project-div "> <div class="float-left image-for-project-container brdr"> <img src="{% static ‘./Images/manworking.webp’ %}" alt="manworking" height="630px"> </div> {% for project in project_details %} <div class=" project-container inline-block "> <h2 class="text-center fnt-black head-portfolio"> {{project.project_name}} </h2> <br> <br> <p

Continue reading

Static files not loading [DJANGO]

Issue My images aren’t loading while using static files from Django and I can fix the problem. Basically I can load neither my favicon <link rel=”shortcut icon” type=”image/png” href=”{% static “images/FAVICON.png” %}”/> and my other image <link rel=”shortcut icon” type=”image/png”

Continue reading

ChartJS : It's not showing in html on Django

Issue I will plot horizontal bar chart in html but it’s not showing. I send 2 variable from views.py are {{top5StockCode}} and {{top5TotalSales}}. The values of {{top5StockCode}} that views.py sent is [‘23166’, ‘21108’, ‘85123A’, ‘48185’, ‘22470’] and {{top5TotalSales}} [2671740, 227322,

Continue reading

return None form django

Issue i have a form fill for register but when i try to save it it involves a none object. the problem is : The view pages.views.essai didn’t return an HttpResponse object. It returned None instead. here is my code

Continue reading

Javascript, showing blob images

Issue So I have this codes in my Django project. I am adding this with jQuery when I upload a file to html input tag which looks like: <input type="file" name="photo" accept="image/*" id="id_photo" multiple> JS (jQuery): …append(`<img scr="${URL.createObjectURL(files[i])}" width="100px" height="100px">`)

Continue reading

Styling django filter form in html

Issue Here’s how my django filter form currently looks: And here’s my html code: <form action="" method="get" class="form-inline"> {{myfilter.form|bootstrap}} <button class="btn btn-primary" type="submit"> Search</button> </form> I am having trouble with the following: How do I bring the filters in center

Continue reading

Django HTML Create Buttons for Not Null Fields Only

Issue I’m fairly new to Django and couldn’t find a way to do this yet. I have a model like this: class Profile(models.Model): user = models.OneToOneField("User", on_delete=models.SET_NULL, null=True) user_name = models.CharField(max_length=50) linkedin = models.URLField(max_length=254, null=True, blank=True) instagram = models.URLField(max_length=254, null=True,

Continue reading