python - Django 查询不支持的格式字符 '"' (0x22)
问题描述
我将一个 store_id 字段从我的索引页面上的链接传递到视图,以便查找它并提供一个显示商店页面。我正在使用 sqlite 后端,但 Model.objcts.get() 函数不会返回对象。它抛出指向我的 .get 行的错误:
ValueError at /store/1001946/
unsupported format character '"' (0x22) at index 192
Request Method: GET
我的观点.py
def store(request, store_id):
print(type(store_id))
sto = StoreStat.objects.get(storeid=store_id)
return render(request, 'stores/store.html', {'store': sto})
我尝试将类型更改为整数,使用编码,但似乎没有任何效果。我也尝试了 .filter() 因为它相似但我得到了同样的错误
我的应用网址
from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('store/<store_id>/',views.store, name='store')
]
项目网址
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('stores.urls')),
path('admin/', admin.site.urls),
]
索引.html
<ol>
{% for store in top %}
<li><a href="{% url 'store' store_id=store.storeid%}">{{
store.storestorename }}</a></li>
{% endfor %}
</ol>
解决方案
我解决了错误。我的数据库中的一个字段包含一个 % 符号。我不得不回去重命名没有它的列,它起作用了。我想这把整个事情都搞砸了!
推荐阅读
- python - Numpy 用另一个数组的特定行和列替换一个数组的特定行和列
- proxy - 运行 SOCKS 代理时,Jupyter Notebook SOCKS 连接失败。想法?
- scala - 理解后如何立即匹配?
- python - 在取消选择窗口之前,Python tk 输入框不活动
- scheduled-tasks - 如何在气流中操作,以便任务重新运行并继续下游任务
- angular - DevExtreme Scheduler Tooltip 单击时调整大小
- apache-flink - 为什么松弛邻接的结果不包括严格邻接的结果?
- php - php a 和 b 玩家连续的石头
- slack - Slack 应用程序和本地存储
- css - 放大文本链接热点而不影响文本或页面外观?