random pic api
This commit is contained in:
parent
aeb4b2e9ad
commit
2718113e2f
|
@ -0,0 +1,3 @@
|
|||
backend/randpic/__pycache__
|
||||
backend/tianyi/__pycache__
|
||||
backend/db.sqlite3
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RandpicConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'randpic'
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,7 @@
|
|||
import json
|
||||
import random
|
||||
|
||||
def get_random_picture():
|
||||
with open("./jsons/pics.json") as f:
|
||||
pictures = json.load(f)
|
||||
return random.choice(pictures)
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
from .random_picture import get_random_picture
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
return redirect("https://cdn.clf3.org/tianyi-random/{}".format(get_random_picture()))
|
|
@ -14,8 +14,9 @@ Including another URLconf
|
|||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import include,path
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('randpic/', include('randpic.urls')),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue