Selaa lähdekoodia

404.html 있으면 404 페이지를 대체

잉여개발기 (SPDV) 6 vuotta sitten
vanhempi
sitoutus
71e8ec5504
5 muutettua tiedostoa jossa 10 lisäystä ja 9 poistoa
  1. 1 0
      .gitignore
  2. 1 1
      app.py
  3. 4 1
      route/main_error_404.py
  4. 3 6
      route/main_file.py
  5. 1 1
      version.json

+ 1 - 0
.gitignore

@@ -2,6 +2,7 @@ __pycache__
 /app_session
 data/set.json
 data/mysql.json
+404.html
 .vscode
 
 *.db

+ 1 - 1
app.py

@@ -681,7 +681,7 @@ def main_views(name = None):
 
 @app.route('/<data>')
 def main_file(data = None):
-    return main_file_2(conn, data)
+    return main_file_2(conn, data) if re.search('\.txt$', data) else main_error_404_2(conn)
 
 # End
 @app.errorhandler(404)

+ 4 - 1
route/main_error_404.py

@@ -3,4 +3,7 @@ from .tool.func import *
 def main_error_404_2(conn):
     curs = conn.cursor()
 
-    return redirect('/w/' + url_pas(wiki_set(2)))
+    if os.path.exists('404.html') and flask.request.path != '/':
+        return open('404.html', 'r').read()
+    else:
+        return redirect('/w/' + url_pas(wiki_set(2)))

+ 3 - 6
route/main_file.py

@@ -3,10 +3,7 @@ from .tool.func import *
 def main_file_2(conn, data):
     curs = conn.cursor()
 
-    if re.search('\.txt$', data):
-        if data == 'robots.txt' and not os.path.exists('robots.txt'):
-            return flask.Response('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/', mimetype='text/plain')
-        else:
-            return flask.send_from_directory('./', data)
+    if data == 'robots.txt' and not os.path.exists('robots.txt'):
+        return flask.Response('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/', mimetype='text/plain')
     else:
-        return redirect('/w/' + url_pas(wiki_set(2)))
+        return flask.send_from_directory('./', data)

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.4-master-17",
+        "r_ver" : "v3.1.4-master-18",
         "c_ver" : "400004",
         "s_ver" : "5"
     }, "stable" : {