2010-03-14 50 views
2

嘿,我一直在做一些改變,我的Django的農業開發ENV,因爲你們中的一些建議Django的。 到目前爲止,我已經設法配置並使用postgres成功運行它。錯誤使用Apache和mod_wsgi的

現在我試圖運行應用程序使用apache2和mod_wsgi,但我遇到了這個小問題後,我遵循django文檔的指導方針。

當我訪問本地主機/ MYAPP /任務這個錯誤引發:

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 
... ... ... 

然後它{在任務%爲T%}突出了一個模板標籤,就像這個問題的根源在那裏,但它在內置服務器上運行良好。

與該頁面相關的視圖是真的是簡單,只需獲取所有Task對象。模板只是將它們顯示在一張桌子上。

另外,一些頁面呈現確定。 不想用代碼填充此問題,因此如果您需要更多信息,我很樂意提供。由於

編輯

所以,這裏是我的觀點:

@login_required 
def tasks(request, msg=''): 
    tasks = Task.objects.all() 
    message = msg 
    return custom_render('user/tasks.html', 
         {'tasks': tasks, 'message':message}, 
         request) 

這裏是我的模板:

{% block main_content %} 

{% if message %} 
    <p id="message" class="info"> 
     {{message}} 
    </p> 
{% endif %} 

<a href="{% url GProject.myapp.views.new_task %}">Nueva Tarea</a> 

    <table id="tasks-table" > 
     <thead> 
      <tr> 
       <th colspan="4" >{{tasks|length}} tareas pendientes</th> 
      </tr> 
      <tr> 
       <th>#</th> 
       <th>Proyecto</th> 
       <th>Título</th> 
       <th>Estado</th> 
      </tr> 
     </thead> 
     <tbody> 
      {% for t in tasks %} 
       <tr id="row-{{t.id}}" class="{% cycle 'row-0' 'row-1' %} priority-{{ t.priority }}"> 
        <td width="25"> 
         <a href="{% url GProject.myapp.views.view_task t.id %}">{{t.id}}</a> 
        </td> 
        <td> 
         <a href="{% url GProject.myapp.views.view_task t.id %}">{{t.project}}</a> 
        </td> 
        <td width="400"> 
         <a href="{% url GProject.myapp.views.view_task t.id %}"> 
          {{t.title}} 
         </a> 
        </td> 
        <td>{{t.get_status_display}}</td> 
       </tr> 
      {% empty %} 
       <tr><td>No tasks</td></tr> 
      {% endfor %} 

     </tbody> 
    </table> 
{% endblock main_content %} 

而且,現在我就在這錯誤

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 

編輯

任務模式是這樣的:

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 

custom_render:

def custom_render(template_name, data_dict, request): 
    return render_to_response(template_name, 
           data_dict, 
           context_instance=RequestContext(request)) 
+0

你可以修改Django源代碼和打印repr的sql和params? 當代碼下devserver和Apache – 2010-03-14 21:45:00

+0

彼得跑了,我真的不知道該怎麼做.. – Nacho 2010-03-15 01:42:24

+0

Django不總是指出模板的正確路線。不要太信任它。 – Macke 2010-03-20 18:52:37

回答

0

只是因爲你沒有遇到問題運行manage.py runserver命令,和你確實遇到使用mod_wsgi的問題,我會查看數據庫權限。

首先,你是否像運行python manage.py runserver一樣運行mod_wsgi?如果不是,則需要授予mod_wsgi用戶權限。作爲一個例子,嘗試這樣的,其中apache是​​運行mod_wsgi的用戶的名稱:

sudo su - postgres 
createuser -S -D -R apache 
psql 
< should now be in the psql shell > 
grant all on database < your database name > to apache; 
+0

也認爲它可能與DB有關,不要做詭計。 – Nacho 2010-03-28 17:34:27