django-views

How to render a variable in a django template?

冷暖自知 提交于 2020-01-02 06:16:50
问题 My goal is to write dynamically some urls of images in the HTML page. Urls are stored in a database. To do so, first I am trying to render a simple varable in a template. Reading the docs and other sources, it should be done in 3 steps: For the configuration: in settings.py TEMPLATES = [ { 'OPTIONS': { 'debug': DEBUG, 'context_processors': [ … 'django.template.context_processors.request', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template

How To Use Django Cycle Tag

情到浓时终转凉″ 提交于 2020-01-02 03:36:05
问题 This hopefully is a pretty easy question. My endgoal is to be able to view my database entries in a table which I can sort via the column headers. I have read the documentation on cycle tags, but don't know they mean by 'row1' and 'row2' : {% for o in some_list %} <tr class="{% cycle 'row1' 'row2' %}"> ... </tr> {% endfor %} Secondly, how would I correctly implement it into my template? I am using a very simple JS library, which will allow the sorting: page.html {% if Variable %} <table class

How to use context with class in CreateView in django?

落爺英雄遲暮 提交于 2020-01-01 19:37:10
问题 How to use context with class in CreateView in django? Before i have: #views.py from django.views.generic import CreateView from cars.models import * def CreateCar(CreateView): info_sended = False if request.method == 'POST': form = FormCar(request.POST, request.FILES) if form.is_valid(): info_sended = True form.save() else: form = FormCar() ctx = {'form': form, 'info_sended':info_sended} return render_to_response("create_car.html", ctx, context_instance=RequestContext(request)) Now, a have,

Django-formwizard and ModelFormSet save

巧了我就是萌 提交于 2020-01-01 19:28:29
问题 I am rewriting a big piece of our application which requires a user to create a Project with Rewards attached to it. The form is broken into different steps, the first two are the normal Project , the next one is the Rewards , and then lastly a simple preview that lets the user flick back and forth to create a perfect Project . my forms.py class BaseRewardFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): super(BaseRewardFormSet, self).__init__(*args, **kwargs) self.queryset =

invalid literal for int() with base 10: 'on' Python-Django

泪湿孤枕 提交于 2020-01-01 09:35:55
问题 i am learning django from official django tutorial. and i am getting this error when vote something from form. this caused from - probably - vote function under views.py here is my views.py / vote function : def vote(request,poll_id): p=get_object_or_404(Poll, pk=poll_id) try: selected_choice = p.choice_set.get(pk=request.POST['choice']) except (KeyError, Choice.DoesNotExist): return render_to_response('polls/detail.html', {'poll':p, 'error_message' : "didint select anything ",}, context

TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'

落花浮王杯 提交于 2020-01-01 08:20:36
问题 my models.py: class Attendancename(models.Model): teacher_name = models.ForeignKey(Teachername, default='Ram') date = models.DateField('Date', default=datetime.datetime.today) intime = models.TimeField('IN-TIME', auto_now=True) outtime = models.TimeField('OUT-TIME', auto_now=True) def hours_conversion(self): startdelta = datetime.timedelta(hours=self.intime.hours, minutes=self.intime.minutes, seconds=self.intime.seconds) enddelta = datetime.timedelta(hours=self.outtime.hours, minutes=self

How to hide a field in django modelform?

跟風遠走 提交于 2020-01-01 06:57:10
问题 For example: class TestModel(models.Model): ref1 = models.ForeignKey(RefModel) text1 = models.TextField() class TestModelForm(ModelForm): class Meta: model = TestModel fields = ('text1') I only allow the user to input text1 field, but when I redefine the post method of my view, I also want to set the ref1 value, how should I do that? I wish I can let TestModelForm has the ref1 field but don't let user modify it, then I can modify the value of request.POSt in post method, and pass it to

Django and ChartJS

大憨熊 提交于 2020-01-01 05:46:08
问题 I'm trying to understand if it it's possible to incorporate dynamic data into a Django Chart JS architecture. I went through a couple of tutorials and ultimately got Django to work with ChartJS and it's very good when I'm able to hard code values and then display the related graphs. What I'm ultimately trying to do is this same exercise with dynamic data from my database. I found this identical question in SO, https://stackoverflow.com/questions/47575896/dynamic-chart-using-django-and-chart

Django: return a StreamingHttpResponse on an existing html page

折月煮酒 提交于 2020-01-01 02:58:07
问题 Since it is better to have a single question for each issue, be patient if is similar to another part of another my question related to the same project. The situation: I have a form on html in which I can set a number and when it is submitted, it is call views.stream_response which pass the value to stream.py and it returns a StreamingHttpResponse and "virtual" blank browser page appears ( /stream_response/ ) in which I can see a progressive number every second up to m : 1 2 3 .. m stream.py

Django and models with multiple foreign keys

可紊 提交于 2020-01-01 02:44:15
问题 I am new to Django and I've been impressed so far by its capabilities. I am playing with more complex models and I am have problem to use them properly. Using Django 1.3, I am trying to write a summary page which would present the three models below with the following structure. In other words, a list of trips with their destinations and activities. Trip 1 Destination 1 Destination 2 Activity 1 Trip 2 Destination 1 Activity 2 Models Trip <-> TripDestination <-> Destination (a trip can have