0
這裏獲取URL是我的urls.py:從請求
from django.conf.urls import include, url
from django.contrib import admin
from stories.views import check, post
urlpatterns = [
url(r'^admin/', admin.site.urls),
url('^.*/$', check),
]
這是我的views.py:
from django.http import HttpResponse
from django.shortcuts import render
from datetime import datetime
from models import Story
from .forms import StoryForm
def check(request):
try:
existing_story = Story.objects.get(name=?URLRequested?)
except Story.DoesNotExist:
return HttpResponse(post(request))
HttpResponse(existing_story.text)
我想轉換輸入的網址重定向404,並用它作爲新對象的名稱。如何才能做到這一點?