HBuilderx 创建新文件命名重合,导致原因文件代码丢失

听者流泪,闻者伤心~~~呜呜呜

世界上总是会有种憨憨(比如我),导致代码失踪

使用HBuilderx,创建一个新的vue文件。(忘记已经有这个文件名)

创建完成后,啊!同名的文件代码不见了!!!

赶紧去线上看一眼,完美这段代码没有提交!

就在我准备再次码代码的时候!!!发现了这个

谢谢你救了孩子一命!!!

记录一下自己憨憨的事

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
当然,我可以帮你完善上述代码,使其能够比较两个文件并计算它们的重合率。以下是相应的代码修改: 1. 修改 `checker/models.py` 文件,添加 `content` 字段用于存储文件内容: ```python from django.db import models class Document(models.Model): title = models.CharField(max_length=200) file = models.FileField(upload_to='documents/') content = models.TextField(blank=True) def __str__(self): return self.title ``` 2. 修改 `checker/views.py` 文件,添加一个的视图函数 `compare_documents` 用于比较两个文件的内容: ```python from django.shortcuts import render, redirect from .models import Document from difflib import SequenceMatcher def compare_documents(request): if request.method == 'POST': document1_id = request.POST['document1'] document2_id = request.POST['document2'] document1 = Document.objects.get(id=document1_id) document2 = Document.objects.get(id=document2_id) # 获取文件内容 content1 = document1.content if not content1: with open(document1.file.path, 'r') as f: content1 = f.read() document1.content = content1 document1.save() content2 = document2.content if not content2: with open(document2.file.path, 'r') as f: content2 = f.read() document2.content = content2 document2.save() # 计算重合率 similarity_ratio = SequenceMatcher(None, content1, content2).ratio() * 100 return render(request, 'checker/result.html', {'document1': document1, 'document2': document2, 'similarity_ratio': similarity_ratio}) documents = Document.objects.all() return render(request, 'checker/compare_documents.html', {'documents': documents}) ``` 3. 创建模板文件 `compare_documents.html` 和 `result.html`: - `compare_documents.html`: ```html <form method="post" action="{% url 'compare_documents' %}"> {% csrf_token %} <label for="document1">Document 1:</label> <select name="document1" required> {% for document in documents %} <option value="{{ document.id }}">{{ document.title }}</option> {% endfor %} </select> <br> <label for="document2">Document 2:</label> <select name="document2" required> {% for document in documents %} <option value="{{ document.id }}">{{ document.title }}</option> {% endfor %} </select> <br> <input type="submit" value="Compare"> </form> ``` - `result.html`: ```html <h2>Comparison Result:</h2> <p>Document 1: {{ document1.title }}</p> <p>Document 2: {{ document2.title }}</p> <p>Similarity Ratio: {{ similarity_ratio }}%</p> ``` 4. 添加 URL 映射: 在 `plagiarism_checker/urls.py` 文件中添加以下代码: ```python from django.urls import path from checker.views import upload_document, compare_documents urlpatterns = [ path('upload/', upload_document, name='upload_document'), path('compare/', compare_documents, name='compare_documents'), ] ``` 这样,你就可以上传文件,并在比较页面中选择两个文件进行对比。结果将显示两个文件重合率。希望这能帮助到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值