jackfrued / jackfrued/Python-100-Days

43.静态资源和Ajax请求 代码疑问

Open
#411 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
187k
Forks
55.8k
PR merge metrics
No merged PRs in 30d

Description

`完成模型迁移之后,我们可以直接使用Django提供的后台管理来添加学科和老师信息,这需要先注册模型类和模型管理类。

from django.contrib import admin

from poll2.forms import UserForm//???缺少模块poll2  不修改会报错找不到Subject
from poll2.models import Subject, Teacher


class SubjectAdmin(admin.ModelAdmin):
    list_display = ('no', 'name', 'create_date', 'is_hot')
    ordering = ('no', )


class TeacherAdmin(admin.ModelAdmin):
    list_display = ('no', 'name', 'detail', 'good_count', 'bad_count', 'subject')
    ordering = ('subject', 'no')


admin.site.register(Subject, SubjectAdmin)
admin.site.register(Teacher, TeacherAdmin)

接下来,我们就可以修改views.py文件,通过编写视图函数先实现“学科介绍”页面。
`
1.这个poll2模块在哪里啊?
pip上也搜不到,尝试更换为models.py导入Subject和Teacher不会报错,但是访问网页127.0.0.1;8000只有一个<所有学科>标题,无更多内容,而且访问127.0.0.1;8000/teachers必报错name 'redirect' is not defined。

Ajax请求 及其后面的还没有放入django。到这步就卡住了

2.请问static文件夹的静态资源(css,js,images)应该放在哪里呢,文中没有细说,是应用app路径下,还是项目路径下,还是和manager.py在同一个目录呢?

本小白第一次发issues,说的不好请见谅。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the tutorial section covering model registration, views.py, Ajax, and static assets, then compare its imports and directory layout with the referenced project. Check where poll2, Subject, Teacher, redirect, and the static folder are defined or expected to be, and document the correct setup and the intended page behavior when / and /teachers are opened.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, django, javascript, python
Domain
documentation, web-dev
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.