我正在将 Django 项目移动到新服务器。
我是 Django 的新手,我不知道应该在哪里上传文件夹。有应该在网站上显示的所有图像。在配置文件中,我没有看到我可以指定的上传文件夹,所以我猜它总是应该是 django 项目的相同位置,或者我找不到它。
位置保存在数据库中。当我将上传的文件放入媒体文件夹时,网址就像domain.co.uk/media/upload/media/images/year/month/day/image_name.ext
旧网站上的一样,网站上的图像仍然丢失。
如果我手动输入 url,所有图像都可见,但 django 似乎看不到文件。
我还检查了 django 日志文件:
2012-05-30 09:13:33,393 ERROR render: Thumbnail tag failed: [in /usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py (line 49)]
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py", line 45, in render
return self._render(context)
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py", line 97, in _render
file_, geometry, **options
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/base.py", line 50, in get_thumbnail
cached = default.kvstore.get(thumbnail)
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/kvstores/base.py", line 25, in get
return self._get(image_file.key)
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/kvstores/base.py", line 123, in _get
value = self._get_raw(add_prefix(key, identity))
File "/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/kvstores/cached_db_kvstore.py", line 26, in _get_raw
value = KVStoreModel.objects.get(key=key).value
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 344, in get
num = len(clone)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1146, "Table 'thumbnail_kvstore' doesn't exist")
2012-05-30 09:13:33,396 DEBUG execute: (0.000) SELECT `freetext_freetext`.`id`, `freetext_freetext`.`key`, `freetext_freetext`.`content`, `freetext_freetext`.`active` FROM `freetext_freetext` WHERE (`freetext_freetext`.`active` = True AND `freetext_freetext`.`key` = office-closed-message ); args=(True, u'office-closed-message') [in /usr/lib/python2.6/site-packages/django/db/backends/util.py (line 44)]
2012-05-30 09:13:33,399 DEBUG execute: (0.000) SELECT `menus_menu`.`id`, `menus_menu`.`name`, `menus_menu`.`slug`, `menus_menu`.`base_url`, `menus_menu`.`description`, `menus_menu`.`enabled` FROM `menus_menu` WHERE (`menus_menu`.`enabled` = True AND `menus_menu`.`slug` = about ); args=(True, u'about') [in /usr/lib/python2.6/site-packages/django/db/backends/util.py (line 44)]
2012-05-30 09:13:33,401 DEBUG execute: (0.000) SELECT `menus_menuitem`.`id`, `menus_menuitem`.`menu_id`, `menus_menuitem`.`title`, `menus_menuitem`.`url`, `menus_menuitem`.`order` FROM `menus_menuitem` INNER JOIN `menus_menu` ON (`menus_menuitem`.`menu_id` = `menus_menu`.`id`) WHERE `menus_menu`.`slug` = about ORDER BY `menus_menuitem`.`order` ASC; args=(u'about',) [in /usr/lib/python2.6/site-packages/django/db/backends/util.py (line 44)]
2012-05-30 09:13:33,404 DEBUG execute: (0.000) SELECT `freetext_freetext`.`id`, `freetext_freetext`.`key`, `freetext_freetext`.`content`, `freetext_freetext`.`active` FROM `freetext_freetext` WHERE (`freetext_freetext`.`active` = True AND `freetext_freetext`.`key` = contactdetails-footer ); args=(True, u'contactdetails-footer') [in /usr/lib/python2.6/site-packages/django/db/backends/util.py (line 44)]
我检查了数据库并且没有表调用thumbnail_kvstore
,但是我有数据库备份,并且在备份文件中该表不存在。
我得到的所有上传文件都在media/uploads/media/
.
此外,我在某些页面上遇到错误:
Syntax error. Expected: ``thumbnail source geometry [key1=val1 key2=val2...] as var``
/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg/sorl/thumbnail/templatetags/thumbnail.py in __init__, line 72
In template /var/www/vhosts/domain.co.uk/sites/apps/shop/products/templates/products/product_detail.html, error at line 34
{% thumbnail image.file "800x700" detail as zoom %}
也许我安装的某些模块的版本不正确。不知道如何解决。
我正在使用 CentOS 6、mod_wsgi、apache、python 2.6。
更新 1.0:
在旧服务器上是 Django 1.3,在新服务器上是 Django 1.3.1
更新 1.1:
我想我知道问题出在哪里。我试过python manage.py syncdb
了,这是输出:
Syncing...
Creating tables ...
The following content types are stale and need to be deleted:
orders | ordercontact
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: no
Installing custom SQL ...
Installing indexes ...
No fixtures found.
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.admin
> django.contrib.admindocs
> django.contrib.markup
> django.contrib.sitemaps
> django.contrib.redirects
> django_filters
> freetext
> sorl.thumbnail
> django_extensions
> south
> currencies
> pagination
> tagging
> honeypot
> core
> faq
> logentry
> menus
> news
> shop
> shop.cart
> shop.orders
Not synced (use migrations):
- dbtemplates
- contactform
- links
- media
- pages
- popularity
- testimonials
- shop.brands
- shop.collections
- shop.discount
- shop.pricing
- shop.product_types
- shop.products
- shop.shipping
- shop.tax
(use ./manage.py migrate to migrate these)
接下来我运行python manage.py migrate
,这就是我得到的:
Running migrations for dbtemplates:
- Migrating forwards to 0002_auto__del_unique_template_name.
> dbtemplates:0001_initial
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
! You *might* be able to recover with: = DROP TABLE `django_template` CASCADE; []
= DROP TABLE `django_template_sites` CASCADE; []
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/management/commands/migrate.py", line 105, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/__init__.py", line 191, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 221, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 292, in migrate_many
result = self.migrate(migration, database)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 125, in migrate
result = self.run(migration)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 99, in run
return self.run_migration(migration)
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 81, in run_migration
migration_function()
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/usr/lib/python2.6/site-packages/django_dbtemplates-1.3-py2.6.egg/dbtemplates/migrations/0001_initial.py", line 18, in forwards
('last_changed', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/db/generic.py", line 226, in create_table
', '.join([col for col in columns if col]),
File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/db/generic.py", line 150, in execute
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1050, "Table 'django_template' already exists")
我也跑了python manage.py migrate --list
,而 uotput 是:
dbtemplates
(*) 0001_initial
(*) 0002_auto__del_unique_template_name
contactform
(*) 0001_initial
(*) 0002_auto__add_callback
(*) 0003_auto__add_field_callback_notes
(*) 0004_auto__add_field_callback_is_closed__add_field_callback_closed
(*) 0005_auto__add_field_callback_url
(*) 0006_auto__add_contact
(*) 0007_auto__add_field_contact_category
(*) 0008_auto__add_field_contact_url
links
(*) 0001_initial
(*) 0002_auto__add_field_category_enabled__add_field_category_order
media
(*) 0001_initial
(*) 0002_auto__del_field_image_external_url__add_field_image_link_url__del_fiel
(*) 0003_add_model_FileAttachment
(*) 0004_auto__chg_field_file_slug__chg_field_image_slug
(*) 0005_auto__chg_field_image_file
(*) 0006_auto__chg_field_file_file
pages
(*) 0001_initial
(*) 0002_auto__chg_field_page_meta_description__chg_field_page_meta_title__chg_
(*) 0003_auto__add_field_page_show_in_sitemap
(*) 0004_auto__add_field_page_changefreq__add_field_page_priority
popularity
(*) 0001_initial
testimonials
(*) 0001_initial
(*) 0002_auto__add_field_testimonial_is_featured
brands
(*) 0001_initial
(*) 0002_auto__add_field_brand_template
(*) 0003_auto__chg_field_brand_meta_description__chg_field_brand_meta_title__ch
(*) 0004_auto__add_field_brand_url
(*) 0005_auto__del_field_brand_image__add_field_brand_logo
collections
(*) 0001_initial
(*) 0002_auto__add_field_collection_discount
(*) 0003_auto__chg_field_collection_meta_description__chg_field_collection_meta
(*) 0004_auto__add_field_collection_is_featured
(*) 0005_auto__add_field_collection_order
discount
(*) 0001_initial
(*) 0002_added_field_discount_description
(*) 0003_auto__add_field_discountvoucher_automatic
(*) 0004_auto__add_field_discountvoucher_collection
(*) 0005_auto__del_field_discountvoucher_collection
(*) 0006_auto__chg_field_discountvoucher_expiry_date
pricing
(*) 0001_initial
(*) 0002_auto__add_pricingrule
product_types
(*) 0001_initial
(*) 0002_auto__add_field_producttype_meta_title__add_field_producttype_meta_des
(*) 0003_auto__add_field_producttype_summary__add_field_producttype_description
products
(*) 0001_initial
(*) 0002_auto__del_field_product_is_featured
(*) 0003_auto__chg_field_product_meta_keywords__chg_field_product_meta_descript
(*) 0004_auto
shipping
(*) 0001_initial
(*) 0002_auto__add_field_shippingmethod_includes_tax__add_field_shippingmethod_
(*) 0003_auto__add_field_shippingmethod_order
(*) 0004_auto__del_field_shippingmethod_tax_rate__del_field_shippingmethod_incl
(*) 0005_auto__del_field_shippingrule_enabled
tax
(*) 0001_initial
(*) 0002_auto__add_field_taxrate_internal_name
(*) 0003_initial_internal_names
(*) 0004_auto__add_unique_taxrate_internal_name
(*) 0005_force_unique_taxrate_name
(*) 0006_auto__add_unique_taxrate_name
之后一些图像源是这样的:
src="cache/1e/bd/1ebd719910aa843238028edd5fe49e71.jpg"
但有些仍然是 src="" 甚至不显示img
标签
另外我已经检查了数据库,并且thumbnail_kvstore
已经创建了表。
any1 可以帮助我处理 syncdb 请求吗?