2013-07-25 63 views
1

這裏是我的model.py從Django管理面板上傳圖像到數據庫

from django.db import models 

class Flower(models.Model): 
    name = models.CharField(max_length = 30) 
    price = models.IntegerField() 
    image = models.ImageField(upload_to = 'static/media') 
    def __unicode__(self): 
     return self.name 

urls.py

from django.conf.urls import patterns, include, url 

from django.contrib import admin 
admin.autodiscover() 

    urlpatterns = patterns('', 
     # Examples: 
     url(r'^$', 'site1.views.home', name='home'), 
     # url(r'^mysite1/', include('mysite1.foo.urls')), 

     # Uncomment the admin/doc line below to enable admin documentation: 
     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 

     # Uncomment the next line to enable the admin: 
     url(r'^admin/', include(admin.site.urls)), 
    ) 

admin.py

from django.contrib import admin 
from site1.models import Flower 

admin.site.register(Flower) 

完全回溯

Traceback: 
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper 
    366.     return self.admin_site.admin_view(view)(*args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view 
    91.      response = view_func(request, *args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 
    89.   response = view_func(request, *args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner 
    196.    return view(request, *args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper 
    25.    return bound_func(*args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view 
    91.      response = view_func(request, *args, **kwargs) 
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func 
    21.     return func(self, *args2, **kwargs2) 
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in changelist_view 
    1233.    'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __len__ 
    85.     self._result_cache = list(self.iterator()) 
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in iterator 
    291.   for row in compiler.results_iter(): 
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in results_iter 
    763.   for rows in self.execute_sql(MULTI): 
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql 
    818.   cursor.execute(sql, params) 
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute 
    40.    return self.cursor.execute(sql, params) 
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute 
    344.    return Database.Cursor.execute(self, query, params) 

Exception Type: DatabaseError at /admin/site1/flower/ 
Exception Value: no such column: site1_flower.image 

我想從管理面板將圖像上傳到我的網站數據庫,因此我可以在任何需要的位置查看此圖像。 但我遇到了一個錯誤:

DatabaseError at /admin/site1/flower/ 
no such column: site1_flower.image 
Request Method: GET 
Request URL: http://127.0.0.1:8000/admin/site1/flower/ 
Django Version: 1.4.3 
Exception Type: DatabaseError 
Exception Value:  
no such column: site1_flower.image 

我該如何克服這個問題。

+0

您的模型看起來不錯。你能提供更多細節 - 比如完整的追溯,你如何試圖訪問它?爲什麼網址中有site1? – chhantyal

+0

還是忍不住以上信息。你可以給admin.py內的目錄結構和代碼嗎? – chhantyal

+0

我編輯了我的輸入 – GaripTipici

回答

0

根據* Exception Value:no such column:site1_flower.image * 我想,你在syncdb後添加了圖像字段。所以,圖像字段不存在於數據庫。 最簡單的方法是根本刪除Flower模型並再次運行syncdb。 或者您可以在您的數據庫中手動創建該字段。 但最好的方法是使用django south

+0

我做了什麼你說的,但我不知道爲什麼,但我現在錯過了管理面板... – GaripTipici