How can I add atribute to webpage in django - django

screenshotI'm following a tutorial to create a website using django. I keep getting this error when running the server.
path('page2',index.webpage2),
AttributeError: module 'website.index' has no attribute 'webpage2'. Did you mean: 'webpage1'?
Don't know what I'm missing, the tutorial ran the server without any problem. The only thing I noticed was that it also gave my a missing os error. I fixed this part.
Thank you for your help

You need to add two views correspoending to the url
def webpage2(request):
pass
def webpage3(request):
pass

Related

Not getting the expected result from Django reverse

hope anyone here will be able to help me out.
I am trying to get the reverse url for a viewset but somehow it's not working.
I will quickly go through what I have done from the moment everything was working fine to the moment the reverse stopped working.
I had a viewset on an app called "card" the reverse was reverse('card:card-list') everything was perfect, then I decided to move the card viewset to a different app called 'company' I did check the new urls structure by using the django_extensions and running the following command on the terminal python manage.py show_urls which gave me the new routing company:card-list I have then changed my reverse to reverse('company:card-list'), but now the code is broken and the reverse is not working as expected.
I have done those changes cause an end point as /api/company/card instead of /api/card/ .
Any ideas on how to solve it?
tks a lot

django error: 'DatabaseOperations' object has no attribute 'geo_db_type'

I have a django project that uses google maps. I wanted to create a GIS application using GeoDjango and Google Maps following this tutorial but went through several issues.
Now I'm stuck, although I decided to remove everything but django still throwing this error regardless I removed all the details related to GIS:
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
I mean there is nothing at all that relate my django project (in the code) to GIS?!
I feel like installing GIS/postgres must have messed up the django default database system.
Any suggestions?
I think I will solve this problem by myself. I found two similar questions here in this place and no one solved them or gave a clear answer.
See this:
GeoDjango error: 'DatabaseOperations' object has no attribute 'geo_db_type'
Which means no clear solution and gotta get around it myself.
This post is thus closed.

Django - ContentType Does Not Exist for own app

I'm trying to learn how to use the ContentTypes framework, I can't seem to get it to find my own apps.
The docs have clear instructions for importing a model from django.contrib.sites, which works for me. However, when I try to substitute my own app and model, I am unsuccessful.
I have a model at MyApp.Events.models.Event. I try to call:
i = ContentType.objects.get(app_label="Events", model="Event")
in response, console prints:
django.contrib.contenttypes.models.DoesNotExist: ContentType matching
query does not exist.
I tried this as well which also failed:
i = ContentType.objects.get(app_label="events", model="event")
I have 'django.contrib.contenttypes' as well as this app listed under installed apps. Is there another setting I am missing to enable this functionality?
Since no one else posted it, here is the solution.
i = ContentType.objects.get(app_label="Events", model="event")
Even if your model is capitalized in your models.py, it gets saved in all lowercase. I don't know if this is Django's idea of funny or PostgreSQL's, so your mileage may vary.

How do you make a django field reference to a python class?

I am working on a project to expand a testing suite that my company uses. One of this things that was asked of me was to link the website to our Github source for code so that the dev team could continue tracking the issues there instead of trying to look in two places. I was able to do this but the problem is that every time the a bug is reported an issue is opened.
I want to add a field to my Django model that tracks an Issue object (from the github3.py wrapper) that is sent to Github. I want to use this to check if an Issue has already been created in Github by that instance of the BugReport and if it has been created, edit the Issue instead of creating another issue in Github that is a duplicate. Does Django have a something that can handle this sort of reference?
I am using Django 1.3.1 and Python 2.7.1
EDIT
I was able to figure my specific problem out using esauro's suggestions. However, as mkoistinen said, If this problem came up in a program where the work-around was not as easy as this one was, should an object reference be created like I had originally asked about or is that bad practice? and if it is okay to make an object reference like that, how would you do it with the Django models?
I'm the creator of github3.py.
If you want to get the issue itself via a number, there are a couple different ways to do this. I'm not sure how you're interacting with the API but you can do:
import github3
i = githbu3.issue('repo_owner', 'repo_name', issue_number)
or
import github3
r = github3.repository('repo_owner', 'repo_name')
i = r.issue(issue_number)
or
import github3
g = github3.login(client_key='client_key', client_secret='client_secret')
i = g.issue('repo_owner', 'repo_name', issue_number)
# or
r = g.repository('repo_owner', 'repo_name')
i = r.issue(issue_number)
otherwise if you're looking for something that's in an issue without knowing the number:
import github3
r = github3.repository('repo_owner', 'repo_name')
for i in r.iter_issues():
if 'text to search for' in i.body_text:
i.edit('...')

Django AdZone and problem in the admin

im would like to use the cool app Django-AdZone, i thinks is a nice work , but i have a litter problem:
i have 2 website, django-adzone is working very nice in one of those website, but in the second website is not working.
I cant see in the django admin the app adzone, i dont know why, i did the same steps for both website, and the second website is not showing the adzone in the admin, the settings.py are similar with relation to adzone.
Any idea?
thanks guys
sorry with my english
ok, now i know where is the error, is not django , is python2.5, here is the error while install
return self.loader.get_data(path)
zipimport.ZipImportError: bad local file header in /home/bismark/lib/python2.5/d jango_adzone-0.2-py2.5.egg