from employee import views
无法正常工作!...服务器给出的页面未找到(404)响应
这是项目结构:
employee
migrations folder
....other files
views.py
hrdjango
__init__.py
settings.py
urls.py
我觉得这些网址无法访问我的视图 这是views.py
from .models import Employee
# Create your views here.
def emp(request):
if request.method == "POST":
form = EmployeeForm(request.POST)
if form.is_valid():
try:
form.save()
return redirect('/show')
except:
pass
else:
form = EmployeeForm()
return render(request,'index.html',{'form':form})
def show(request):
employees = Employee.objects.all()
return render(request,"show.html",{'employees':employees})
def edit(request, id):
employee = Employee.objects.get(id=id)
return render(request,'edit.html', {'employee':employee})
def update(request, id):
employee = Employee.objects.get(id=id)
form = EmployeeForm(request.POST, instance = employee)
if form.is_valid():
form.save()
return redirect("/show")
from django.contrib import admin
from django.urls import path
from employee import views
urlpatterns = [
path('admin/', admin.site.urls),
path('emp', views.emp),
path('show',views.show),
path('edit/<int:id>', views.edit),
path('update/<int:id>', views.update),
path('delete/<int:id>', views.destroy),
]
urls.py
我有未解决的进口“雇员”消息
答案 0 :(得分:1)
这是项目urls.py还是应用程序级别的urls.py?如果这是您的应用程序级别urls.py,则导入应为import {View, Text, Button} from "react-native";
。如果它是项目级别的urls.py,请发布您的文件结构,以便我们可以查看导入结构是否错误。
答案 1 :(得分:0)
我认为更好的解决方案是对单独的应用程序使用单独的urls.py文件,然后将其包含在您的根URL中。
在您的应用中创建一个urls.py。
在您的根urls.py
中from django.urls import path,include
urlpatterns = [
...,
...,
path('employee/', include('employee.urls')),
]