回答編集履歴

1

関数の追加

2016/12/27 09:38

投稿

momosan
momosan

スコア176

test CHANGED
@@ -1 +1,33 @@
1
1
  function内ではないのにreturnしているから出ているエラーではないでしょうか?
2
+
3
+ returnをprintに変えれば表示はされると思います。
4
+
5
+ もし関数使いたいなら
6
+
7
+
8
+
9
+ ```
10
+
11
+ from django.db import models
12
+
13
+ import requests
14
+
15
+
16
+
17
+ def code_check(r):
18
+
19
+ if r.status_code == 301 or r.status_code == 302:
20
+
21
+ return str(r.status_code)+"redirect"
22
+
23
+
24
+
25
+ r = requests.get(input(), allow_redirects=False)
26
+
27
+ code_check(r)
28
+
29
+ ```
30
+
31
+ defで関数定義できます。
32
+
33
+ 今モジュールがなくて試せてないですがこれで一応動くはず…