django-templates

Put a <a> hyperlink in a django message [duplicate]

筅森魡賤 提交于 2019-12-03 22:42:51
This question already has answers here : Closed 3 years ago . How do I output HTML in a message in the new Django messages framework? (7 answers) I'm using django messages and i want to put an hyperlink in it. view.py: from django.contrib import messages def my_view(request): messages.info(request,"My message with an <a href='/url'>hyperlink</a>") Obviously, in my page, i see the html code and no hyperlink. How to treat the message as an htlml code ? Hope this is clear. Strings in Django templates are automatically escaped. You don't want your raw HTML to be auto-escaped, so you should either

Django admin page error

陌路散爱 提交于 2019-12-03 22:28:08
I was creating a Django app. Doing so i enabled the Django admin site and i could see it working fine. Then i created some models and inserted data into it through the form in my app. But i am not able to see the entered values through admin panel of Django. I found that its because i havent included an admin.py file in my application folder. Then i created an admin.py file, ran syndb and tried. Now its throwing an error ImportError at /admin/ No module named UniversityDetails.models I will paste my admin.py, models.py and project folder structure. Please help me to solve this. Models.py from

Displaying uploaded images in the template - Django

二次信任 提交于 2019-12-03 21:50:26
I am trying to display uploaded images to a template for my imaginary vegetable catalogue. I have a page to add a new vegetable and upload images . The main template is a list of vegetables which will later have thumbnails. Now, when viewing the detail page of the vegetable I want to display its images, but the template is only displaying the string 'VegetableImage Object' in place of an image, even with img tags. I am confused because the template has obviously found the images but they are displayed just as a generic string. models.py class Vegetable(models.Model): title = models.CharField

Django FormWizards: How to painlessly pass user-entered data between forms?

梦想与她 提交于 2019-12-03 21:47:31
问题 I'm using the FormWizard functionality in Django 1.4.3. I have successfully created a 4-step form. In the first 3 steps of the form it correctly takes information from the user, validates it, etc. In Step #4, it right now just shows a "Confirm" button. Nothing else. When you hit "Confirm" on step #4, does something useful with it in the done() function. So far it all works fine. However, I would like to make it so that in step 4 (The confirmation step), it shows the user the data they have

Django template outliner

感情迁移 提交于 2019-12-03 21:36:08
I'm trying to obtain a visual representation of the templates of a Django project, as a hierarchy. The main idea is to get a list of template names as the default template loading machinery would return (ie honoring TEMPLATE_DIRS , TEMPLATE_LOADERS , etc.) and then parsing the templates looking for {% block %} and {% extends %} tags, in order to create a tree structure. Finally use grapviz for the visualization. I'm not sure if it's a viable approach. But just to start, how can I load the templates the way I described? Or maybe, does something similar already exist? Normally, templates are

Return Django Models for Template Rendering after an Ajax Request

[亡魂溺海] 提交于 2019-12-03 21:27:04
I would like to create an AJAX-based search for my webpage. So far I am able to send the form data and make the appropriate call to my Django model. What I am having a hard time with is just sending the Queryset back and having it rendered using the Django templating system. Your help/advice is greatly appreciated. Here is the code I am working with. views.py if request.is_ajax(): if request.method == 'POST': format = 'json' mimetype = 'application/json' try: q = request.POST['obj'] o = Object.objects.filter(name__icontains=q) return render_to_response( 'project_view_objects.html', {'username'

How to validate mulitple forms in a single formView class Django

萝らか妹 提交于 2019-12-03 21:24:57
I have a formView class as you can see below:- view.py class ThreadForm(FormView): template_name = 'thread.html' form_class = ThreadModelForm success_url = '/success' def form_valid(self, form): # This method is called when valid form data has been POSTed. # It should return an HttpResponse. print form.cleaned_data return super(ThreadForm, self).form_valid(form) def get_context_data(self, **kwargs): context = super(ThreadForm, self).get_context_data(**kwargs) context['second_form'] = MessageModelForm return context thread.html {form.as_p} {second_form.as_p} SUBMIT In my template thread.html ,

How to make master-detail model / screen in Django?

假装没事ソ 提交于 2019-12-03 17:33:33
One thing that I allways collide is how to implement a master-detail application with Django. The tipical example is the Invoice and InvoiceLines. The things to discuss are: how to structure code for saving, loading, etc. master and detail models views: files and templates, templates for detail lines, how to add dynamically autocalculated fields (like the total on parent row), where this code goes ? Edit/Additions: About autocalculated fields, here is my first solution, http://pastebin.com/ZGqNnHuC , would not it be better in the save method of model? The master model needs values from detail

How to get object from PK inside Django template?

大城市里の小女人 提交于 2019-12-03 17:28:21
问题 Inside django template, I would like to get object's name using object's pk. For instance, given that I have pk of object from class A , I would like to do something like the following: {{ A.objects.get(pk=A_pk).name }} How can I do this? 回答1: From the docs on The Django Template Language: Accessing method calls: Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within

Django best practice with foreign key queries

馋奶兔 提交于 2019-12-03 17:16:42
models.py class Category(models.Model): name = models.CharField(max_length=50) class SubCatergory(models.Model): parent_category = models.ForeignKey(Category) name = models.CharField(max_length=100) views.py def all_products(request): c = Category.objects.all() s = SubCatergory.objects.all() return render_to_response('all_products.html', {'c':c, 's':s}) all_products.html {% for category in c %} <h1>{{ category.name }}</h1> <ul> {% for sub in s %} {% if category.id == sub.parent_category.id %} <li>{{ sub.name }}</li> {% endif %} {% endfor %} </ul> {% endfor %} Just wondering if above is best