我想通过html将mongodb中的数据投影到Django中的网站。我该怎么做?
下面是我在settings.py中的操作我想通过html将mongodb中的数据投影到Django中的网站。我该怎么做?,django,mongodb,django-models,django-views,mongoengine,Django,Mongodb,Django Models,Django Views,Mongoengine,下面是我在settings.py中的操作 DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'jobs_db', 'HOST': 'localhost', 'PORT': '27017', 'username': '', 'password': '', } } from mongoengine import * conn
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'jobs_db',
'HOST': 'localhost',
'PORT': '27017',
'username': '',
'password': '',
}
}
from mongoengine import *
connect('jobs_tbl')
class jobs_tbl(models.Model):
job_company = models.CharField(max_length=200,null=True)
job_location = models.CharField(max_length=200,null=True)
job_title = models.CharField(max_length=200,null=True)
在models.py中
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'jobs_db',
'HOST': 'localhost',
'PORT': '27017',
'username': '',
'password': '',
}
}
from mongoengine import *
connect('jobs_tbl')
class jobs_tbl(models.Model):
job_company = models.CharField(max_length=200,null=True)
job_location = models.CharField(max_length=200,null=True)
job_title = models.CharField(max_length=200,null=True)
Views.py内容
from mongoengine import *
connect('jobs_tbl')
def home(request):
job=jobs_tbl.objects.all()
context={
'jobs':job,
}
return render(request,'Jobseeker.html',context)
<div class="container card">
<h1>Available openings</h1>
<div class="card-body">
<table class="table table-hover">
<tr>
<th>Name</th>
<th>Position</th>
<th>Description</th>
</tr>
{% for c in jobs %}
<tr>
<td>{{c.job_company}}</td>
<td>{{c.job_location}}</td>
<td>{{c.job_title}}</td>
<td><a href="{% url 'apply' %}" class="btn btn-info btn-sm" type="submit">Apply</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
html内容
from mongoengine import *
connect('jobs_tbl')
def home(request):
job=jobs_tbl.objects.all()
context={
'jobs':job,
}
return render(request,'Jobseeker.html',context)
<div class="container card">
<h1>Available openings</h1>
<div class="card-body">
<table class="table table-hover">
<tr>
<th>Name</th>
<th>Position</th>
<th>Description</th>
</tr>
{% for c in jobs %}
<tr>
<td>{{c.job_company}}</td>
<td>{{c.job_location}}</td>
<td>{{c.job_title}}</td>
<td><a href="{% url 'apply' %}" class="btn btn-info btn-sm" type="submit">Apply</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
可用空缺
名称
位置
描述
{作业%中的c为%1}
{{c.job_company}
{{c.job_location}
{{c.job_title}
{%endfor%}
我对web开发、mongodb、html非常陌生。我已经在网上尝试了好几天,但是找不到解决这个问题的方法。非常感谢您的帮助