django-views

Getting Objects by id in Django

丶灬走出姿态 提交于 2020-01-05 08:29:31
问题 I'm trying to get data by id in my django app. The problem is that I don't know the kind of id the user will click on. I tried adding the below code in my views but I'm getting this error: ValueError at /findme/ invalid literal for int() with base 10: 'id' Request Method: GET Request URL: http://127.0.0.1:8000/findme/ Django Version: 1.4 Exception Type: ValueError Exception Value: invalid literal for int() with base 10: 'id' Exception Location: C:\Python27\lib\site-packages\django\db\models

Django Template not displaying model data

ぐ巨炮叔叔 提交于 2020-01-05 07:41:26
问题 I've looked through different tutorials and Stack Overflow questions and I'm not sure why I'm still running into this issue: I am running into an issue with displaying my model data onto my template, I can see that the python code is executing, but no matter what I've tried I can't get my data to come through, my relevant code snippets are below: models.py class GoogleData(models.Model): placeID = models.CharField(max_length=999) name = models.CharField(max_length=200) phoneNumber = models

Django Template not displaying model data

柔情痞子 提交于 2020-01-05 07:41:09
问题 I've looked through different tutorials and Stack Overflow questions and I'm not sure why I'm still running into this issue: I am running into an issue with displaying my model data onto my template, I can see that the python code is executing, but no matter what I've tried I can't get my data to come through, my relevant code snippets are below: models.py class GoogleData(models.Model): placeID = models.CharField(max_length=999) name = models.CharField(max_length=200) phoneNumber = models

Django - Redirect to another domain from View

你离开我真会死。 提交于 2020-01-05 07:05:14
问题 I'm trying to redirect from mydomain.com to google.com. There are a couple of answers on stackoverflow that asume the following is working: return HttpResponseRedirect('google.com') or return redirect('google.com') But it doesn't it. This just redirects the page to itself and appends the google.com part so it comes out like this: www.mydomain.com/google.com What throws a 404 of course.. My view now looks like the following: class MyView(TemplateView): def get(self, request, *args, **kwargs):

Randomizing again in Django

血红的双手。 提交于 2020-01-05 07:02:49
问题 When I generate a quiz in django, the question value before if request.method == 'POST': is one and then changed. Follow the screenshots. views.py questao = Questao.objects.annotate(resp_count=models.Count(models.Case(models.When(resposta__usuario=request.user, then=1),output_field=models.IntegerField()))).filter(resp_count=0,tipoQuestao=1).order_by("?").first() print (questao) if request.method == 'POST': print (questao) respostaform = RespostaForm(request.POST or None) if respostaform.is

Randomizing again in Django

谁说我不能喝 提交于 2020-01-05 07:02:43
问题 When I generate a quiz in django, the question value before if request.method == 'POST': is one and then changed. Follow the screenshots. views.py questao = Questao.objects.annotate(resp_count=models.Count(models.Case(models.When(resposta__usuario=request.user, then=1),output_field=models.IntegerField()))).filter(resp_count=0,tipoQuestao=1).order_by("?").first() print (questao) if request.method == 'POST': print (questao) respostaform = RespostaForm(request.POST or None) if respostaform.is

Django - using different apps together in a project

怎甘沉沦 提交于 2020-01-05 06:52:16
问题 In the basic Django tutorials and documentations I have found so far, apps are treated as some standalone parts of the project. I haven't yet found, though, solutions of using them together in a complex project. We can sign up at some url domain/signup , and it is handled by users.views.signup . For a GET request signup renders signup.html . For a POST request, after evaluating the posted data, it either renders signup.html with some message or registers a new user, logs him/her in and

How do you bind a model to two other, already related models, and display the information?

风格不统一 提交于 2020-01-05 05:56:19
问题 Apologies if the title is not up to scratch, I wasn't sure how to word my problem. Please feel free to edit in a better one. Here is what I am trying to do: I am trying to create a relational database using a few different models. The idea is: A contract is unique Any contract can have (and share) any number of projects Unique information needs to be stored about each specific project for a specific contract So far, the first two bullet points I have working as expected. The third point seems

Can any one explain how can i pass arg or kwargs from redirect to another view?

亡梦爱人 提交于 2020-01-05 05:27:54
问题 I am trying to let the manager of a site I'm developing send mail to the members and send get a confirmation page. The send mail is working and sending the mail OK, but in the confirmation i want him to get the the list of people he sent the mail to. So, i need to send the users_list from one function (view) to the other in the directs and read it in the other view sending it to render_to_response. I've read a lot and tried reverse and many other things i read over the web but can't seem to

What's the correct way to print a matrix with labels in a Django template?

[亡魂溺海] 提交于 2020-01-05 04:35:10
问题 I want to do something very simple in Django: Print a matrix as an HTML table, and add labels for the rows and columns. These are the variables in my view: matrix = np.array([ [101, 102, 103], [201, 202, 203], ]) colnames = ['Foo', 'Bar', 'Barf'] rownames = ['Spam', 'Eggs'] I want a to get a table that looks like this: Foo Bar Barf Spam 101 102 103 Eggs 201 202 203 My template code looks like this: <table> <tr> <th></th> {% for colname in colnames %} <th>{{ colname }}</th> {% endfor %} </tr>