Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 服务器无法识别Views.py。服务器赢得';t识别文件中的错误代码或引发异常_Django_Django Views - Fatal编程技术网

Django 服务器无法识别Views.py。服务器赢得';t识别文件中的错误代码或引发异常

Django 服务器无法识别Views.py。服务器赢得';t识别文件中的错误代码或引发异常,django,django-views,Django,Django Views,我正在努力展示我通过管理GUI创建的一些模型对象。 我无法通过我的查看功能让它们显示在网页上 (编辑:)在做了一些挖掘之后,我意识到当我破坏views.py文件时,服务器不会引发异常(所有其他文件都可以正常工作)。为什么服务器不读取视图文件 所有文件都位于/jobboard中。工作板列在设置文件中已安装的应用程序中,工作板中的所有其他文件都可以正常工作 我还注意到,我在项目文件夹中没有admin.py。这正常吗 Views.py: from django.shortcuts import ren

我正在努力展示我通过管理GUI创建的一些模型对象。 我无法通过我的查看功能让它们显示在网页上

(编辑:)在做了一些挖掘之后,我意识到当我破坏views.py文件时,服务器不会引发异常(所有其他文件都可以正常工作)。为什么服务器不读取视图文件

所有文件都位于/jobboard中。工作板列在设置文件中已安装的应用程序中,工作板中的所有其他文件都可以正常工作

我还注意到,我在项目文件夹中没有admin.py。这正常吗

Views.py:

from django.shortcuts import render
from django.views.generic import TemplateView
from django.contrib.auth.decorators import staff_member_required
from .models import JobPost
from django.utils import timezone


def jobs(request):   
    JobPost.objects.filter(published_date__lte=timezone.now()).order_by('published_date')

    latest_post_list = JobPost.objects.order_by('-pub_date')

    context = {

        'deadline': deadline,
        'created_at': created_at, 
        'wordcount':wordcount, 
        'jobtaken':jobtaken,
        'JobPost':JobPost,
        'latest_post_list':latest_post_list,
    }

    return render(request, 'jobboard/jobs.html', context=context)
URL.py:

from django.contrib import admin
from django.urls import path, re_path, include
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from login import views

urlpatterns = [

    path('admin/', admin.site.urls),
    #re_path(r'^login/$', auth_views.login(template_name = 'accounts/login.html'), name='login'),
    re_path(r'^signup/$', views.signup, name='signup'),
    path('login/', include('login.urls')),
    path('', views.index, name='index'),
    path('accounts/', include('django.contrib.auth.urls')),
    path('jobs/', views.jobs, name='jobs'),
    path('users/', include('users.urls')),
    path('users/', include('django.contrib.auth.urls')),
]
目录结构:

gpproject
│   ├── db.sqlite3
│   ├── gp.sublime-project
│   ├── gp.sublime-workspace
│   ├── grad
│   │   ├── __init__.py
│   │   ├── Procfile1
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── settings.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── wsgi.cpython-35.pyc
│   │   ├── settings.py
│   │   ├── static
│   │   │   ├── office.jpeg
│   │   │   └── pics
│   │   │       └── office.jpeg
│   │   ├── urls.py
│   │   ├── views.py
│   │   └── wsgi.py
│   ├── jobboard
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0002_auto_20180716_1122.py
│   │   │   └── __init__.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   ├── login
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── __init__.py
│   │   │   └── __pycache__
│   │   │       ├── 0001_initial.cpython-35.pyc
│   │   │       └── __init__.cpython-35.pyc
│   │   ├── models.py
│   │   ├── __pycache__
│   │   │   ├── admin.cpython-35.pyc
│   │   │   ├── apps.cpython-35.pyc
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── models.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── views.cpython-35.pyc
│   │   ├── static
│   │   │   └── pics
│   │   │       └── office.jpeg
│   │   ├── templates
│   │   │   ├── login
│   │   │   │   └── office.jpeg
│   │   │   ├── loginbutton.html
│   │   │   ├── logoutbutton.html
│   │   │   ├── navbar.html
│   │   │   ├── registration
│   │   │   │   ├── login.html
│   │   │   │   ├── logintut.html
│   │   │   │   ├── password_reset_complete.html
│   │   │   │   ├── password_reset_confirm.html
│   │   │   │   ├── password_reset_done.html
│   │   │   │   ├── password_reset_email.html
│   │   │   │   └── password_reset_form.html
│   │   │   └── signup.html
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── manage.py
│   ├── oldbackupdb.sqlite3
│   ├── templates
│   │   ├── base.html
│   │   ├── footer.html
│   │   ├── Header.html
│   │   ├── index2.html
│   │   ├── index.html
│   │   ├── jobpost.html
│   │   ├── jobs.html
│   │   ├── navbar.html
│   │   ├── oldHeader.html
│   │   ├── sidenav.html
│   │   ├── signup.html
│   │   └── userdropdown.html
│   ├── universities.xcf
│   └── users
│       ├── admin.py
│       ├── apps.py
│       ├── forms.py
│       ├── __init__.py
│       ├── migrations
│       │   ├── 0001_initial.py
│       │   ├── __init__.py
│       │   └── __pycache__
│       │       ├── 0001_initial.cpython-35.pyc
│       │       └── __init__.cpython-35.pyc
│       ├── models.py
│       ├── __pycache__
│       │   ├── admin.cpython-35.pyc
│       │   ├── forms.cpython-35.pyc
│       │   ├── __init__.cpython-35.pyc
│       │   ├── models.cpython-35.pyc
│       │   ├── urls.cpython-35.pyc
│       │   └── views.cpython-35.pyc
│       ├── tests.py
│       ├── urls.py
│       └── views.py
├── gradproofworkspace.code-workspace
├── index1.html
├── office.jpeg
├── Pipfile
├── Pipfile.lock
├── Procfile
├── README.md
├── requirements.txt
└── runtime.txt

感谢您的帮助

您没有导入作业视图。在您的url.py中,名称
视图
仅从
登录
应用程序导入

from login import views
...
path('jobs/', views.jobs, name='jobs'),
您可以这样更改它:

from jobboard.views import jobs
...
path('jobs/', jobs, name='jobs'),

谢谢赫肯,这为我指明了正确的方向。更准确地说,我只是缺少这一行代码:


作业板导入视图中的

作业中的
函数出现语法错误<代码>上下文:{
应该是
上下文={
。请确保问题中的代码是您实际运行的代码,并且语法是有效的python。此外,您的
JobPost
模型没有
pub\u date
字段或
published\u date
字段,因此此代码也会引发有关此问题的异常。有趣的是,当我运行服务器时,它会显示“System Identity”如果没有问题(0)”。
jobs
view函数会在运行时引发异常,我认为在导入时也是如此,这是由于语法错误(除非python将其解释为类型提示?)。您确定没有使用其他文件中的视图吗?不仅存在语法错误,还有几个名称错误。您根本无法运行。您没有看到错误的事实表明此代码甚至没有被导入,更不用说运行了。请发布您的目录结构,准确显示此视图文件的位置,以及您的URL.py。您最初的路由为什么能够工作仍然有点神秘,因为大概没有登录.views.jobs
视图,所以您在访问
/jobs/
时会遇到异常。