django - 如何映射/调度 Django url?
问题描述
我正在尝试制作一些地图......以在市场上使用。
所以我尝试使用 Django,Python。但是有一些与 url 映射相关的问题。
这就是问题所在。
jeobjeom_code = c[5] = pk = SAF11050
我想创建一些链接,例如“RAW_SoMae_MaeJang_Info_detail/SAF11050”,但没有成功。
如果 jeobjeom_code 只是 int,它可以工作!但如果 jeobjeom_code 是字符串,则根本不起作用。
我猜 c[5] 使用是错误的......但我不知道如何解决它......
NoReverseMatch at /Maps_DaeLi_PanMae Reverse for 'RAW_SoMae_MaeJang_Info_detail' 关键字参数 '{'pk': 'c[5]'}' 未找到。
-models.py
class RawSomaeMaejangInfo(models.Model):
jeobjeom_code = models.CharField(db_column='JeobJeom_Code', primary_key=True, max_length=50) # Field name made lowercase.
latitude = models.CharField(db_column='Latitude', max_length=100, blank=True, null=True) # Field name made lowercase.
longitude = models.CharField(db_column='Longitude', max_length=100, blank=True, null=True) # Field name made lowercase.
-urls.py
urlpatterns =[
path('RAW_SoMae_MaeJang_Info_detail/<int=pk>', views.RAW_SoMae_MaeJang_Info_detail, name='RAW_SoMae_MaeJang_Info_detail'),
-Maps_DaeLi_PanMae.html
var tmpl = '<div style="font-family: dotum, arial, sans-serif;font-size: 18px; font-weight: bold;margin-bottom: 5px;">#{title}</div>' +
'<table style="border-spacing: 2px; border:s 0px"><tbody><tr>' +
'<tr><td style="color:#767676;padding-right:12px">check</td>' +
'<td><a href="{% url 'RAW_SoMae_MaeJang_Info_detail' pk='c[5]' %}" >link</a></td>' +
-views.py
def Maps_DaeLi_PanMae(request):
Maps_DaeLiJeom_list = RawSomaeMaejangInfo.objects.all()
context = {"Maps_DaeLiJeom_list":Maps_DaeLiJeom_list}
return render(request, 'app/Maps_DaeLi_PanMae.html', {"Maps_DaeLiJeom_list":Maps_DaeLiJeom_list})
解决方案
虽然我不明白c[5]的目的是什么.. 我在您的代码中发现了两个可能导致问题的错误..
你的网址格式应该是这样的..
path('RAW_SoMae_MaeJang_Info_detail/<int:pk>/', views.RAW_SoMae_MaeJang_Info_detail, name='RAW_SoMae_MaeJang_Info_detail'),
在模板中,您已经遍历Maps_DaeLiJeom_list ..
{% for Maps_DaeLiJeom in Maps_DaeLiJeom_list %}
<a href="{% url 'RAW_SoMae_MaeJang_Info_detail' pk=Maps_DaeLiJeom.pk %}" >link</a>
{% endfor %}
推荐阅读
- api - 以相反的顺序从 API 加载项目
- python-3.x - 机器学习问题:我在测试数据中创建了一个新列,但不是中值,而是用 NaN 填充
- calculated-columns - 从 Cockroachdb 中的 JSONB 列(包含 json 数组)创建计算列
- python - < & <= 在 Python 中不起作用,但是在调试时它会从根文件夹中打开一些其他文件
- javascript - 如何使用 Javascript 快速搜索 JSON?
- java - 如何将 ArrayList 存储到 Android 中的 sharedPreferences 中
- flutter - 如何从 Flutter 中的 listView 中删除 null 项
- php - 为什么 jQuery 单击事件侦听器未在 WooCommerce 按钮上注册?
- javascript - 您如何从 Firebase 存储中提取图像列表?
- spring-boot - 弹簧反应的弹簧安全会话超时