django 404错误页面404错误页面

hec6srdp  于 2022-12-01  发布在  Go
关注(0)|答案(4)|浏览(200)

我已经通过cPanel将Django部署在我的站点子域www.example.com中apps.example.com,我的Django应用程序www.example.com的主页apps.example.com/adsense-eligibility-checker可以正常工作,但是当我填写表单并点击***提交***按钮时,它会重定向到404错误页面,而不是运行mainApp/views.py中的第二个函数***scanned(requests)***。
这位于mainApp/views.py目录中:

def home(request):
        return render(request, 'home.html')
        
    
    def scanned(request):
        email = request.POST['email']
        site = request.POST['site']
        rating = request.POST['stars']
        source = request.POST.getlist('source')
......
        return render(request, "result.html", {'rMsg':rMsg,'result0':result0, 'result1':result1,'site': site,'show_site':show_site, 'vips':m1, 'domain':domain, 'site_age':site_age, 'sent': sent})

MainApp内部介绍/urls.py:

from django.urls import path
from.import views

urlpatterns=[
    
    path('', views.home, name='home'),
    path('scanned/', views.scanned, name='scanned')

]

内部主页.html:

{% extends 'main.html' %}
{% load static %}
{% block content %}
{% csrf_token %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" href="{% static 'style.css' %}">

  <form method='POST' action="/scanned/" class='FormBody'>
    {% csrf_token %}
    <div id='tab'>
      <h2>Adsense Eligibility Checker</h2>
      <fieldset class='siteAndEmail'>
        <legend>Site & Email</legend>
        <div class='form-wrapper'>
          <div class='full-input'>
            <label for="site">Your Site URL</label>
            <input type="domain" name='site' class='input' placeholder="https://yoursite.com">
          </div>

          <div class='full-input'>
            <label for="email">Your Email</label>
            <input type="text" name='email' class='input' placeholder="youremail@gmail.com">
          </div>
        </div>
      </fieldset>
      <fieldset class='siteAndEmail reached'>
        <legend>How did you reached us?</legend>
        <label class='c1'>
          <input type="checkbox" name='source' value='Facebook' />
          <i id='icon' class="fa fa-facebook"
            style='background:linear-gradient(white,lightblue); color:dodgerblue;'></i>
          Via Facebook
        </label>
        <label class='c1'>
          <input type="checkbox" name='source' value='Google Search' />
          <i id='icon' class="fa fa-google"
            style='background:linear-gradient(160deg,yellow, dodgerblue,rgb(255, 0, 119), rgb(157, 255, 0)); color:white;'></i>
          Via Google Search
        </label>
        <label class='c1'>
          <input type="checkbox" name='source' value='Quora' />
          <i id='icon' class="fa fa-quora"
            style='background:linear-gradient(rgb(236, 0, 0),rgb(158, 0, 0)); color:white;'></i>
          Via Quora
        </label>
        <div style='display:inline-block;'>
          OTHERS
          <input type="text" name='source'
            style="background:rgba(255, 255, 255, 0.048);font-family:'Courier New', Courier, monospace; border:0px; border-bottom:1px solid rgba(0, 0, 0, 0.568);line-height:1.5em; padding-left:3px;"
            placeholder="others" />

        </div>
      </fieldset>
    </div>
    <fieldset class='siteAndEmail'>
      <legend>Rate Our Service</legend>
      <div class='rating'>
        <label>
          <input type="radio" name="stars" value="1" />
          <span class="icon">★</span>
        </label>
        <label>
          <input type="radio" name="stars" value="2" />
          <span class="icon">★</span>
          <span class="icon">★</span>
        </label>
        <label>
          <input type="radio" name="stars" value="3" checked />
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
        </label>
        <label>
          <input type="radio" name="stars" value="4" />
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
        </label>
        <label>
          <input type="radio" name="stars" value="5" />
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
          <span class="icon">★</span>
        </label>
      </div>
    </fieldset><br>
    <button class='butn'> S C A N </button>

</form>
{% endblock %}

结果.html内:

{% extends 'main.html' %}
{% load static %}
{% block content %}
{% load static %}
{% csrf_token %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="{% static 'style2.css' %}">
<div class='borders'>
<h2>R E S U L T Of Scanning Via Adsense Eligibility Checker</h2>
<div id='result'>
<ul style='text-align:left;'>
    <li type='disc'>
        {{result1}}
        <script>
        if ('{{rMsg}}'== ''){
            document.write('<br>');
            console.log('rMsg Level 1');
        }
        else {
            document.getElementById('rmsg').innerHTML=('{{rMsg}}');
            console.log('rMsg Level 2');
        }
        
    </script>
    {{result0}}
    <a id='rmsg'></a><br><a alt='What are the pages required for Adsense Approval' title='Pages Required For Adsense Approval' style='display:inline-block; text-decoration:none; color:rgb(196, 255, 87);' href='https://blog.example.com/check-website-eligibility-for-google-adsense/#What_are_the_pages_required_for_Adsense_approval'>
 Pages Required For Adsense Approval
    </a>
</li>
    <li type='disc'>{{domain}}</li>
    <li type='disc'>{{site_age}}</li>
    <p style='text-align:center;'><i id='icon' class="fa fa-globe" style='background:linear-gradient(rgba(0, 250, 146, 0.596),rgba(0, 140, 255, 0.637)); color:rgb(255, 255, 255);'></i>
        <a href='{{site}}' style='display:inline-block; text-decoration:none; color:rgb(0, 255, 179);'>{{show_site}}</a> is awesome.
    
    </p>
</ul>
</div>

</div>

<p style='font-size:medium;font-family:serif;'>{{sent}}</p>
<br>
<a style='font-family:Consolas;font-size:larger;font-weight:bolder;display:inline-block; text-decoration:none; color:rgb(196, 255, 87);' href='https://blog.example.com/check-website-eligibility-for-google-adsense/#What_are_the_minimum_requirements_for_Adsense_Approval' title='Minimum requirements for Adsense Approval'>Min-Requirements for Adsense Approval</a>

{% endblock %}
ghhkc1vu

ghhkc1vu1#

还需要添加type属性,如果action必须转到当前url,则可以将其留空

<button class='butn' type='submit'> S C A N </button>
guicsvcw

guicsvcw2#

更改此网站views.py:

def scanned(request):
        email = request.POST['email']
        site = request.POST['site']
        rating = request.POST['stars']
        source = request.POST.getlist('source')
......
        # Inside function
        return render(request, "result.html", {'rMsg':rMsg,'result0':result0, 'result1':result1,'site': site,'show_site':show_site, 'vips':m1, 'domain':domain, 'site_age':site_age, 'sent': sent})

另外,通过name改变你的动作。例如:

<form method='POST' action="{% url 'scanned' %}" class='FormBody'>
rqcrx0a6

rqcrx0a63#

您的表单URL操作有问题,请更正并更改按钮类型以提交和重定向您的URL,而不是呈现

return redirect('html_page')
5rgfhyps

5rgfhyps4#

鼻涕虫adsense-eligibility-checker的最后一个字符“r”消失在adsense-eligibility-checke\scanned中,最后,我添加了action='adsense-eligibility-checker\scanned',效果非常好。

相关问题