Note that there are some explanatory texts on larger screens.

plurals
  1. POError in django using Apache & mod_wsgi
    text
    copied!<p>Hey, I've been doing some changes to my django develpment env, as some of you suggested. So far I've managed to configure and run it successfully with postgres.</p> <p>Now I'm trying to run the app using apache2 and mod_wsgi, but I ran into this little problem after I followed the guidelines from the django docs.</p> <p>When I access localhost/myapp/tasks this error raises:</p> <pre><code> Request Method: GET Request URL: http://localhost/myapp/tasks/ Exception Type: TemplateSyntaxError Exception Value: Caught an exception while rendering: argument 1 must be a string or unicode object Original Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py", line 71, in render_node result = node.render(context) File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py", line 126, in render len_values = len(values) File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 81, in __len__ self._result_cache = list(self.iterator()) File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 238, in iterator for row in self.query.results_iter(): File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 287, in results_iter for rows in self.execute_sql(MULTI): File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 2369, in execute_sql cursor.execute(sql, params) File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 19, in execute return self.cursor.execute(sql, params) TypeError: argument 1 must be a string or unicode object ... ... ... </code></pre> <p>And then it highlights a {% for t in tasks %} template tag, like the source of the problem is there, but it worked fine on the built-in server.</p> <p>The view associated with that page is <em>really</em> simple, just fetch all Task objects. And the template just displays them on a table.</p> <p>Also, <em>some</em> pages get rendered ok. Don't want to fill this Question with code, so if you need some more info I'd be glad to provide it. Thanks</p> <p><strong>EDIT</strong></p> <p>So, here is my view:</p> <pre><code>@login_required def tasks(request, msg=''): tasks = Task.objects.all() message = msg return custom_render('user/tasks.html', {'tasks': tasks, 'message':message}, request) </code></pre> <p>And here is my template:</p> <pre><code>{% block main_content %} {% if message %} &lt;p id="message" class="info"&gt; {{message}} &lt;/p&gt; {% endif %} &lt;a href="{% url GProject.myapp.views.new_task %}"&gt;Nueva Tarea&lt;/a&gt; &lt;table id="tasks-table" &gt; &lt;thead&gt; &lt;tr&gt; &lt;th colspan="4" &gt;{{tasks|length}} tareas pendientes&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Proyecto&lt;/th&gt; &lt;th&gt;Título&lt;/th&gt; &lt;th&gt;Estado&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; {% for t in tasks %} &lt;tr id="row-{{t.id}}" class="{% cycle 'row-0' 'row-1' %} priority-{{ t.priority }}"&gt; &lt;td width="25"&gt; &lt;a href="{% url GProject.myapp.views.view_task t.id %}"&gt;{{t.id}}&lt;/a&gt; &lt;/td&gt; &lt;td&gt; &lt;a href="{% url GProject.myapp.views.view_task t.id %}"&gt;{{t.project}}&lt;/a&gt; &lt;/td&gt; &lt;td width="400"&gt; &lt;a href="{% url GProject.myapp.views.view_task t.id %}"&gt; {{t.title}} &lt;/a&gt; &lt;/td&gt; &lt;td&gt;{{t.get_status_display}}&lt;/td&gt; &lt;/tr&gt; {% empty %} &lt;tr&gt;&lt;td&gt;No tasks&lt;/td&gt;&lt;/tr&gt; {% endfor %} &lt;/tbody&gt; &lt;/table&gt; {% endblock main_content %} </code></pre> <p>Also, now I'm getting <em>this</em> error:</p> <pre><code>TypeError at /admin/tareas/ argument 1 must be a string or unicode object Request Method: GET Request URL: http://localhost/gpro/admin/tareas/ Exception Type: TypeError Exception Value: argument 1 must be a string or unicode object Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py in _cursor, line 105 Python Executable: /usr/bin/python Python Version: 2.5.4 </code></pre> <p><strong>EDIT</strong></p> <p>Tasks model looks like this:</p> <pre><code>class Task(models.Model): project = models.ForeignKey(Project) title = models.CharField(max_length=128) description = models.TextField(max_length=1500) effort = models.IntegerField(null=True, blank=True) priority = models.IntegerField(max_length=1, null=True, blank=True, choices=PRIORITY_VALUES) severity = models.IntegerField(max_length=1, null=True, blank=True, choices=SEVERITY_VALUES) asignee = models.ForeignKey(User, blank=True, null=True, related_name='asignee') milestone = models.ForeignKey(Milestone, blank=True, null=True) created_by = models.ForeignKey(User, blank=True, null=True, related_name='created_by') status = models.IntegerField(max_length=1, choices=STATUS_VALUES, default=1) resolution_comment = models.CharField(max_length=1500, null=True, blank=True) #comentario al resolver la task due_date = models.DateField(blank=True, null=True) created_on = models.DateTimeField(auto_now_add = True) #print def __unicode__(self): return self.title </code></pre> <p>custom_render:</p> <pre><code>def custom_render(template_name, data_dict, request): return render_to_response(template_name, data_dict, context_instance=RequestContext(request)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload