django-templates

Django - Timeuntil Tag output abbreviation

心不动则不痛 提交于 2019-12-02 06:26:10
问题 I'm using django timeuntil template tag and the output is something like 8 hours, 15 minutes . Does anyone have any idea how I can make the output to be like 8 Hr, 15 Min ? 回答1: Take a look to timesince from django source code: chunks = ( (60 * 60 * 24 * 365, ungettext_lazy('%d year', '%d years')), (60 * 60 * 24 * 30, ungettext_lazy('%d month', '%d months')), (60 * 60 * 24 * 7, ungettext_lazy('%d week', '%d weeks')), (60 * 60 * 24, ungettext_lazy('%d day', '%d days')), (60 * 60, ungettext

Django: Using a variable as the URL namespace?

纵饮孤独 提交于 2019-12-02 06:22:12
I'm trying to create a submenu for a sports site. Each sport would need its own submenu. The problem I'm having is I need the namespace itself to be dynamic in someway. SportListView returns the sport so I can then filter the news articles by the sport. Views: class SportListView(ListView): template_name="sports/sport-home.html" context_object_name='sport_list' def get_context_data(self, **kwargs): context = super(SportListView, self).get_context_data(**kwargs) context['sport_menu'] = get_object_or_404(Sport, sport_slug=self.kwargs['sport_slug']) return context Template: <nav class="navbar

How to you pass a validation error to a template

只愿长相守 提交于 2019-12-02 06:15:34
I have a IP validation rule such as : >>> validate_ipv46_address("1.1.1") Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/django/core/validators.py", line 125, in validate_ipv46_address raise ValidationError(_('Enter a valid IPv4 or IPv6 address.'), code='invalid') ValidationError: [u'Enter a valid IPv4 or IPv6 address.'] And I have a form that is currently functioning like... class CacheCheck(forms.Form): type = forms.TypedChoiceField(choices=TYPE_CHOICES, initial='FIXED') record = forms.TypedChoiceField(choices=RECORD

How to use the Django Usurena “mugshot” template variable

ⅰ亾dé卋堺 提交于 2019-12-02 05:23:20
问题 I'm trying to use Userena in our Django website, but I can't seem to figure out how to use the template tag to display the mugshot. I have tried the following to spit out the URL within an image tag: <img src="{{ owner_profile.get_mugshot_url }}"> and <img src="{{ profile.get_mugshot_url }}"> Anyone have some insight?? Thanks! 回答1: based on alican answer, just put following code in your template: <img src="{{ user.get_profile.get_mugshot_url }}" /> 回答2: Use the following code to display

Django: UnboundLocalError: local variable 'company' referenced before assignment

谁说我不能喝 提交于 2019-12-02 05:19:00
I am trying to make a url field in my detail view by passing two primary key in it... This is what I have done in urls.py: url(r'^company/(?P<pk1>\d+)/groupdetail/(?P<pk2>\d+)/$',views.group1DetailView.as_view(),name='groupdetail'), And in my views: def get_object(self): pk1 = self.kwargs['pk1'] pk2 = self.kwargs['pk2'] company = get_object_or_404(company, pk=pk1) group1 = get_object_or_404(group1, pk=pk2) return group1 I am getting error in this line: company = get_object_or_404(company, pk=pk1) And in my group1 list view I have done this: <a href="{% url 'accounting_double_entry:groupdetail'

Javascript syntax error in Django Template when variable value is missing

陌路散爱 提交于 2019-12-02 04:57:19
I have a Django template with an AJAX menu (where clicking on different menu items reloads a part of the page). Each menu click invokes a Django view function through AJAX and returns some data to be shown on the page. I am loading all the JS required for all the menu items in the main page only (as I learnt that it is not a good idea for AJAX to return JS in a <div> and then use eval() to execute it). Since I am loading all the JS on the menu's main page only, the data obviously isn't there for other menu options at start since it will come later when the corresponding view is invoked (when

google visualization-Click event on barchart isStacked: true

杀马特。学长 韩版系。学妹 提交于 2019-12-02 02:25:00
I'm trying to display the total value of a barchart where 'isStacked: true' on a <span> located on top of the chart when I click on a bar. My reference to explore the capability of google.visualization.events.addListener started here. When I click the a bar I recieved this error: Uncaught TypeError: Cannot read property 'row' of undefined or when I change the row to column Uncaught TypeError: Cannot read property 'column' of undefined Any pointers is really appreciated. Here's my django template: <script type="text/javascript"> $(document).ready(function(){ {% for staff_name, staff_id in

How to add attribute '_meta' to an object?

99封情书 提交于 2019-12-02 02:22:01
问题 I'm trying to add the django-voting app to my project. I don't know how to use it in my templates, so I'm adding a new template tags for voting up or down when an user click in buttons. I don't know if there's a well form to do it. My problem is with these kind of line in the template tag: obj = Place.objects.filter(id=object_id) Vote.objects.record_vote(obj, self.user, +1) django print: Caught AttributeError while rendering: 'Place' object has no attribute '_meta' How I can add the attribute

Using Django to summarize Report

穿精又带淫゛_ 提交于 2019-12-02 02:18:52
I'm trying to produce a table that will show the total maturity amounts for each financial institution that a plan has. A plan is the term I use for person. So each person can have multiple investments. I'm having trouble creating a table that will do this correctly. Currently I have a report that displays each investment sorted by Maturity Date, i.e. 2011,2012, etc. At the bottom I would like to place this summary table, but my query displays duplicates of each financial institution, due to being able to have multiple investments. My current query: list = Investment.objects.all().filter(plan

Pass request.user to view without altering the url

老子叫甜甜 提交于 2019-12-02 01:36:07
I'm trying to write a view where the current logged in user's information is retrieved. My view is written as below, and it works perfectly fine as long as I pass the user to the view in the URL. def index(request, username, template="index.html"): user = get_object_or_404(User, username__iexact=username) expression_qs = Expression.objects.all().order_by('-created') album_qs = Album.objects.all().filter(head__isnull=False, is_public=True).order_by('-created') user_following = user.relationships.following() following_expressions = positive_filter(expression_qs, user_following, 'user') following