我有使用sqlite作为数据库的Django应用。我不会制作能够下载该sqlite文件的视图。
到目前为止,这是我得到的:
def backup(request):
"""Return Sqlite3 db file, if Sqlite3 db is used."""
import settings
db_engine = settings.DATABASES['default']['ENGINE']
#db_engine = 'JUST_FOR_TESTING'
if db_engine == 'django.db.backends.sqlite3':
db_path = settings.DATABASES['default']['NAME']
response = HttpResponse(mimetype='application/x-sqlite3')
response['Content-Disposition'] = 'attachment; filename=%s' % db_path
response.write(db_path)
return HttpResponse(response)
else:
return HttpResponse("settings.DATABASES['default']['ENGINE'] is %s,<br />\
only for 'django.db.backends.sqlite3' online backup is posible." % (db_engine))
我所缺少的是如何将文件添加为附件。
还可以通过某种方式仅下载特定表吗?
哔哔one
相关分类