Python 如何修复&x201C'&引用;不是有效的UUID;

Python 如何修复&x201C'&引用;不是有效的UUID;,python,python-3.x,django,django-3.0,Python,Python 3.x,Django,Django 3.0,我想让用户通过拖放来重新排序内容表。当我按下“提交订单”按钮(重新订购后)时,我出现错误: ValidationError at /save-group-ordering/ ['“” is not a valid UUID.'] Request Method: POST Request URL: http://127.0.0.1:8000/save-group-ordering/ Django Version: 3.0.2 Exception Type: ValidationError E

我想让用户通过拖放来重新排序内容表。当我按下“提交订单”按钮(重新订购后)时,我出现错误:

ValidationError at /save-group-ordering/
['“” is not a valid UUID.']
Request Method: POST
Request URL:    http://127.0.0.1:8000/save-group-ordering/
Django Version: 3.0.2
Exception Type: ValidationError
Exception Value:    
['“” is not a valid UUID.']

Traceback Switch to copy-and-paste view
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site- 
packages\django\db\models\fields\__init__.py in to_python
return uuid.UUID(**{input_form: value}) …
▶ Local vars
C:\Python 3.7\lib\uuid.py in __init__
raise ValueError('badly formed hexadecimal UUID string') …
▶ Local vars
During handling of the above exception (badly formed hexadecimal UUID string), another exception occurred:
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\core\handlers\exception.py in inner
response = get_response(request) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\core\handlers\base.py in _get_response
response = self.process_exception_by_middleware(e, request) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site- packages\django\core\handlers\base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\views\decorators\http.py in inner
return func(request, *args, **kwargs) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\tasks\views.py in save_new_ordering
group = Task.objects.get(lookup_id__exact=lookup_id) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\manager.py in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in get
clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in filter
return self._filter_or_exclude(False, *args, **kwargs) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs)) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in add_q
clause, _ = self._add_q(q_object, self.used_aliases) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in _add_q
check_filterable=check_filterable, …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in build_filter
condition = self.build_lookup(lookups, col, value) …
▶ Local vars
C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in build_lookup
查找=查找\u类(lhs、rhs)… ▶ 局部变量 C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\lookups.py ininit self.rhs=self.get\u prep\u lookup()… ▶ 局部变量 C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site packages\django\db\models\lookups.py在get\u prep\u lookup中 返回self.lhs.output_字段。获取准备值(self.rhs)… ▶ 局部变量 C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site packages\django\db\models\fields\u init\uuu.py在get\u prep\u值中 将self.to_python(值)… ▶ 局部变量 C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site packages\django\db\models\fields\u init\u.py in to\u python 参数={'value':值}… ▶ 局部变量

我只是从django开始工作,我不明白我做错了什么

这是我的模特

class Task(models.Model):
    
project = models.ForeignKey(Project, null=True, on_delete=models.CASCADE)
title = models.CharField(max_length=300, null=True)
complete = models.BooleanField(default=False)
deadline = models.DateField('Deadline of the task (year, month, day)', default=date.today)
created = models.DateTimeField(auto_now_add=True,null=True)
lookup_id = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
order = models.IntegerField(blank=False, default=100_000)

def __str__(self):
return self.title

def deadline_func(self):
days = self.deadline - date.today()
return days
这是我的URL.py

from django.urls import path
from . import views

urlpatterns = [
path('' , views.projects_list, name="list"),
path('create_project/' , views.createProject, name="create_project"),

path('deadline_project/<str:pk>' , views.deadlineProject, name="deadline_project"),

path('update_project/<str:pk>' , views.updateProject, name="update_project"),
path('delete_project/<str:pk>' , views.deleteProject, name="delete_project"),
path('create_task/<str:pk>' , views.createTask, name="create_task"),

path('save-group-ordering/', views.save_new_ordering, name='save-group-oldering'),

path('deadline_task/<str:pk>' , views.deadlineTask, name="deadline_task"),

path('update_task/<str:pk>' , views.updateTask, name="update_task"),
path('delete_task/<str:pk>' , views.deleteTask, name="delete_task"),  
]
这是我的表格

class TaskForm(forms.ModelForm):

class Meta:
model = Task
fields = '__all__'

class OrderingForm(forms.Form):
ordering = forms.CharField()
这是我的html

<table class="raz">
                
<tbody id="groups">
{% for task in project.task_set.all %}

                

<tr data-lookup="{{ folder.lookup_id }}">
<td style="width: 50px;"><span class="handle"><img src=" static/images/Up_Down.png " alt="Up_Down_icon"></span></td>

{% if task.complete == True %}
<td style="width: 50px;"class="ch"><input class="checkbox" type="checkbox" name="complete" id="id_complete" checked ></td>
{% else %}
<td style="width: 50px;"><input class="checkbox" type="checkbox" name="complete" id="id_complete"  ></td>
{% endif %}

<td style="width: 550px;"><p>{{task.title}}</p></td>

<td style="width: 50px;"><a class="calendar" href="{% url 'deadline_task' task.id %}">
<img src=" static/images/calendar.png " alt="calendar_icon">
</a></td>

<td style="width: 50px;"><a href="{% url 'update_task' task.id %}" class="edittask">
                            <img src=" static/images/pencil_icon.png " alt="pencil_icon">
</a></td>
                                
<td style="width: 50px;"><a href="{% url 'delete_task' task.id %}" class="deletetask">
                            <img src=" static/images/trash.png " alt="trash_icon">
</a></td>

</tr>

{% endfor%}
</tbody>
                
</table>


<form id="orderingForm" method="post" action="{% url 'save-group-oldering'  %}">
{% csrf_token %}
<input type="hidden" id="orderingInput" name="ordering">
</form>

<button id="saveOrdering">Save ordering</button>

{project.task_set.all%}
{%if task.complete==True%}
{%else%}
{%endif%}
{{task.title}}

{%endfor%} {%csrf_令牌%} 保存订单
因此,当我们在URL中传递id时,就像在本例中一样,UUID将是一个字符串,有时它会将端点视为UUID,因此我建议您将UUID放在下面

如果你有两个网址

abc/efg and abc/<str:uuid>
abc/efg和abc/
那么订单应该是

abc/efg
abc/<str:uuid>
abc/efg
abc/
如果我们不这样做,它就会读出来
<强> ABC/STR:UUID 第一,考虑 EFG作为UUID >P>请显示错误的堆栈跟踪,否则很难知道它是从哪里来的。请问您到底需要什么“查找UID”?也许它甚至不需要,只是慢慢地写下你的appqa123——我使用了“lookup_id”,因为“id”被用作外键,我不确定我是否可以使用它(“id”)作为标识来保持排序顺序
abc/efg
abc/<str:uuid>