我已经开始使用 Django 3.0 和 Python 3.7 学习网络开发。我是在Windows OS的默认端口8000上使用 virtualenv-16.7.8 的虚拟环境中完成此操作的。我在 urls.py 文件中定义了两个网址,即 admin / 和 posts / 。我在 urls.py 和 posts.urls.py 文件中的urlpatterns变量分别如下所示:
urls.py
public function getStories($reel_ids = null)
{
$variables = ['precomposed_overlay' => false, 'reel_ids' => []];
if (empty($reel_ids)) {
$response = Request::get(Endpoints::getUserStoriesLink(),
$this->generateHeaders($this->userSession));
if ($response->code !== static::HTTP_OK) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
if (empty($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'])) {
return [];
}
foreach ($jsonResponse['data']['user']['feed_reels_tray']['edge_reels_tray_to_reel']['edges'] as $edge) {
$variables['reel_ids'][] = $edge['node']['id'];
}
} else {
$variables['reel_ids'] = $reel_ids;
}
$response = Request::get(Endpoints::getStoriesLink($variables),
$this->generateHeaders($this->userSession));
if ($response->code !== static::HTTP_OK) {
throw new InstagramException('Response code is ' . $response->code . '. Body: ' . static::getErrorBody($response->body) . ' Something went wrong. Please report issue.', $response->code);
}
$jsonResponse = $this->decodeRawBodyToJson($response->raw_body);
if (empty($jsonResponse['data']['reels_media'])) {
return [];
}
$stories = [];
foreach ($jsonResponse['data']['reels_media'] as $user) {
$UserStories = UserStories::create();
$UserStories->setOwner(Account::create($user['user']));
foreach ($user['items'] as $item) {
$UserStories->addStory(Story::create($item));
}
$stories[] = $UserStories;
}
return $stories;
}
posts.urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('posts/', include('posts.urls'))
]
前几天,我能够在本地主机服务器上访问两个页面。但是今天,在启动环境之后,我可以无错误地访问 posts / 页面,但不能访问 admin / 页面。每当我尝试通过“ 无法访问此站点”消息和显示“ Python停止工作”的Windows提示访问admin /页面时,服务器都会自动退出。 ”。
自上次停用virtualenv并关闭计算机以来,我没有对任何项目文件夹进行任何更改。可能是什么原因?