@JoshMenzel You clearly have more logic there than a simple return 'normal'. Remove everything from it except the 'return "normal"' statement to make sure the route is actually correct.
If you get the "normal" string when trying to access your /debug route, then your problem is not with the route.
It's with the logic you have in it, which is different.
Notice the 'GET /debug' close to the bottom, returning HTTP-404 (Not Found)
That's what you should get in your log when you actually reach your server. If you're not getting that, then you're not really communicating with your server.
A simple command such as: curl -X GET localhost:5000/debug should be able to hit your server if it's running.
(Note that I'm in GNU+Linux, so that's not a Windows command)
Whatever client application you're trying to use must be the one complaining that it can't communicate with the server at all, so it fails to 'GET /debug'.
Check for exit codes returned by your client application trying to hit the server
And then check documentation for what they mean.
It's it's decent, there should be an exit code stating that it couldn't establish a connection or something else more specific, if the error is different.
Well, I think your issue is deeper than what you thought. Perhaps you should remove the nginx reverse proxy to see if your app is reachable at all (you can launch it as: flask run 0.0.0.0:5000)
So that it accepts connections from any remote IP. (Note that I'm assuming your PC is not accessible to the wider internet)
I must continue working on a few things, so I can't /debug much more for you (pun intended). You should have enough now to figure out the rest, IMHO.
another code-philosophy question: if i'm building a django project where all my apps have separate functions (i.e. - each app does its own job well), but they share lots of things (e.g. - i might have a "car" object, but a "build" app that builds cars and a "drive" app that drives them)
and i don't plan on releasing any of this in such a way that people would want to use one app but no the other
... what's the point of having separate apps?
why not just have a main folder—and if i want to split up views/models/etc. just put different folders within the main folder w/ their own views, models, etc.
"what's the point of having separate apps?" Keeping your sanity. It's the same reason why you don't write all the code for a program in a single function; you break it down into logical components to keep your mental sanity, allow your code to be understandable/maintainable, and to avoid wishing that you had a time machine to go back in time and murder your past self for not having done better at organizing the code and causing misery to your future self.
Besides, others who need to work with your code will thank you.
well—that answers the question "what's the point of organizing your code well?" i mean, literally, what's the point of having separate apps (like, specifically, there seems to be a big emphasis on apps and a particular django-default structure)
This is especially true if you're working on non-trivial systems. Django does not expect its recommended practices to be as useful if you're dealing with trivial applications. If your application grows to a non-trivial size, you will begin to appreciate the point of grouping things into logical components. A django app is a logical component of your larger project.
Several years ago I worked on a Django-based project that had inventory, orders, and more things. There was an inventory app, an orders app, and so on. The orders app had a dependency on the inventory app, of course, and that's not a problem, but they were separate.
project ----templates ----tests ----main --------migrations --------models ------------cars.py (this is where the car model is defined) --------build_car -------------views -------------forms --------drive_car -------------views -------------forms
yes. but the implication was "what's the point of having specifically separate apps?" you're answering a much more general question. i know why one should organize their code well. i'm asking, moreso, why is django's default app-structure more advantageous than, say, the above structure?
It's always a trade-off. Engineering is about trade-offs. One negative could be that if your apps are trivial, then it might appear "over-engineered" (until they become non-trivial, if they ever do)
i'm asking specifically about django apps, not just general separate-your-code logic (unless you're saying that the only reason apps are useful is because it follows a separate-your-code logic, which is kind of what i'm leaning towards :l )
ah, dude, i think you're misunderstanding me here. let me try to rephrase:
Let's say we have two ways of structuring code which _both_ do a good job of separating things out so that they're easily maintained and well put together
why would one choose django's default app structure over the other way of structuring code?
in fact it looks to me that it'd be easier to just have a single migrations folder so that apps which depend on one another can't get into weird migration loops (in case they're both updated simultaneously, and one model in one app depends on another model in another app)
@AmagicalFishy Ok, I get what you mean now. If both do a good job on the specific criteria you're using, then there's no advantage or disadvantage for any of the two, b/c both are doing good. It would, I think, boil down to personal preference, though in that case, I'd look at different criteria to see what other pros/cons you can find. The django project structure is, after all, only a recommendation. Personally, I'd stick with the recommendations if you're starting out.
OTOH, if you already have enough experience to know better (gotchas, caveats, etc), then why not change it, if you know the consequences of the change?
aaah, ok, cool. tyvm :D i've been using django for a little while—but always felt cleaner w/ a slightly tweaked structure. i was just making sure that there wasn't some huge thing i'd be getting screwed on by tweaking the structure
@JoshMenzel Ah yes, that has gotten me too. It's just that you had said your route was '/debug' and not '/debug/', and you said you were GETting '/debug', so I didn't think that was the problem
Catching up, interesting. A fellow implementing my path dispatch protocol in JS and I were recently discussing certain test cases. Issuing automatic permanent redirects for collections missing trailing slashes to the URI with trailing slash, and for resources the inverse.
(In the case of "object dispatch", collection being an instance of a class, a resource being a method or attribute thereof.)
Sometimes it's hard to decide between "errors should never pass silently" and "practicality beats purity".
some kind of indication would probably help more than none at all
in the absence of doc strings, one would normally end up processing the function even more carefully than one that had doc strings, before realising it was meant to be ignored, unless the expectation is set in advance
@ALollz I answered it, also fixed up the title to be clearer. Since the reopen, I can't see which targets were suggested as dupes, but I'm not aware it's a dupe.
maybe I have a pretty specific sub-case then. This is not something that is going to be public, it's meant to be a simple script for testing something, and I might as well make it readable
@Arne the way I see it, it's a hurdle. I'll want not to use it because the code looks less nice, and ._ is not a series of characters I find easy to type
I don't want to discourage people from using these methods
just "well, don't worry about it, if you're just trying to figure out how to normally use this class"
If I notice foo.bar() and I wonder what bar does I'll do help(foo.bar) in an interactive shell unless I know where to find the docs online
@towc eh, okay
we'll get back to it when times change and "minimal effort done to write maintainable code" is no longer an enterprise luxury
I just don't know what you expect when you ask for input here.
I guess it's my mistake for reading "is there an established way to do what I want" as "I want to do it right". "let's do this quick" is a completely different thing. Not doing anything is quick. You're done, you can call it a day.
Can someone please add reject and edit this to add the numpy tag? I missed what the proposed edit added, but accepting will reverse the fluff that I removed
@towc I read all your comments but I'm not understanding too well: you have 12 internal methods () that you want to have readable code, but without docstrings, but users should be able to figure out they're internal so they don't need to read them. Have a look at how pandas organizes itself. Suggest you shunt them into a separate file or subdirectory and import them, to keep users from worrying about their contents....
It sounds like you're reaching the point where one monolithic file is too long to be coherent, so you should make this a package? (yes I know it's easier and less error-prone to copy a single file, especially when your users are like "What's pip? Why isn't it on my command line? Why did it break on version x?")
this is literally an internal tool I'm using to work as a server to test a client. The server will need to be implemented by someone else, so I just wanted the tests to be able to be some kind of reference
this code isn't going to be ran by anyone else, and might not even end up being read
I've half paid attention to this discussion and you seem to be throwing any sensible approach away as "enterprise-ish" as though good structure etc. is something to be avoided unless absolutely necessary
@towc _prefix convention doesn't imply "This function is hopelessly obscure/ cryptically written", merely "a) No external code should directly call this function b) its signature(/behavior/return value) may be subject to change c) You should not need to read all its code in order to understand the class"
I'm not asking/expecting you to be sorry for anything. It's an observation you you seem to be painting yourself into a corner on some principle I can't grasp
@towc Instead of saying 'enterprise-ish', perhaps tell us who will be deploying this, are they expected to have any Python knowledge, let alone working up-to-date versions of pip and python 3.7.x on their paths, what's their expectation of legibility vs robustness vs support? Are you deploying it from git? a tarball? If users break it, will they send panic messages to the VP at 3am, or will they be able to fix it?
this is literally an internal tool I'm using to work as a server to test a client. The server will need to be implemented by someone else, so I just wanted the tests to be able to be some kind of reference
and the 2 messages after that
the point of those messages was to close the conversation
I just saw a question by someone from COMU University. I'd never heard of it, so a quick Google to see where it is and the description starts "With its 49.791 students, Çanakkale Onsekiz Mart University (COMU) is one of the most competitive universities in Turkey..." I guess they account for the limbs lost in the obstacle course for the top 50. (I can never read . as anything but decimal)
when you make a scatter matrix with pandas it outputs like this
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df932780>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df9579e8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df902c50>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df8aaeb8>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df8dc160>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df8843c8>,
....
<matplotlib.axes._subplots.AxesSubplot object at 0x7f79df6fb668>,
yeah, I guess you could manually relocate those subplot objects into a figure...but I think their position (as in subplot location) would have to be changed
yeah, try that and see what happens (I don't know)
@Skyler google "matplotlib change axes figure" or something like that
it might be as simple as changing ax.figure
it also might not be possible
@aaren - It's not working because the way the axes stack for a figure works has been changed in newer versions of matplotlib. Axes deliberately aren't supposed to be shared between different figures now. As a workaround, you could do this fig2._axstack.add(fig2._make_key(a), a), but it's hackish and likely to change in the future. It seems to work properly, but it may break some things. — Joe KingtonDec 7 '12 at 13:21
you're probably better off computing and plotting the scatters yourself...
The following shows how to "move" an axes from one figure to another. This is the intended functionality of @JoeKington's last example, which in newer matplotlib versions is not working anymore, because axes cannot live in several figures at once.
You would first need to remove the axes from the...
This website I frequent has a banner advertising an "incoming new look" alongside a countdown reading "30days". I think it's supposed to be exciting but I find it ominous
Could it be because I know that new version releases usually come with bugs, outages, and clueless support?
I have a function that loads a setting from a file. Because that setting file may not be initialised yet/exist I check if it exists, calling the function to create it if necessary, *then* import the setting from the file. Is this bad form/a bad idea? I could simply house this function in a separate script, but doing that purely for this reason seems silly, whereas keeping it with the other scripts dealing with settings and creating/editing/writing to the settings file seems logical.
Although where possible I don't actually bother reading from the file immediately after I create it. Since presumably I still have the data I used to initialize the file on-hand already
#e.g. I prefer this:
def get_or_create(filename):
if isfile(filename):
with open(filename) as file:
return json.load(file)
else:
data = {"foo": "bar"}
with open(filename, "w") as file:
json.dump(data, file)
return data
#over this:
def get_or_create(filename):
if not isfile(filename):
data = {"foo": "bar"}
with open(filename, "w") as file:
json.dump(data, file)
with open(filename) as file:
return json.load(file)
@toonarmycaptain I worry that when you say "import" you mean the actual import statement. I don't consider it bad design to put configuration options inside a .py file... As long as you're not trying to do anything fancy with it, like autogenerate the file at runtime if it doesn't exist.
As soon as you graduate from "I only need to retrieve values that are definitely present and will never change over the lifetime of the program's execution", then I'd be inclined to use a non-py file format for config data.
I have a site I was looking into where their webservice was providing all the "options" for the front end to display, Now I realized the JSON response to angular had close to 100k objects, this was chugging render on the front end, is there anyway around this other than perhaps "loading" on each drop down box ? or is question too vague...
I'd be inclined to do something AJAXy like fetch values in batches of 100 per request, only doing so when the user is about to reach the end of the list
@Kevin Fair enough, that's really the part of the pattern I was querying. The issue being if the import is at the top, outside of a try-except, it'll obviously error when it doesn't find it. But maybe it should be JSON. It just seemed simpler to do from settings import setting, then deal with any potential changes by modifying the var and writing to the file.
@roganjosh 50-55 states/territories always feels crazy to me, coming from Australia where it's like...8-10 max, usually.
Having an import at the global scope but inside a try-except is a little crufty to my eye, but not actually a flag of any color. I've seen it done in professional code bases.
@roganjosh Unclear; Poe's Law applies. I've seen designs like this alongside obvious joke designs like a phone number slider, or a "is this your number? [no, guess again]" label/button. But the thousand-element dropdown is just barely not-impractical enough to be real.
Certainly I can imagine real-world applications where the simplest implementation really would be a zillion element drop down. M.R.'s instincts are correct that there's got to be a better way.
@roganjosh Coming from Western Australia to Texas, and hearing Texans talk about everything being bigger, and driving distances always makes me laugh...
My own work project has a couple lists whose number of values is in the low hundreds. We have a custom widget that makes it easy to search/filter though.
Our biggest plain old dropdown has, like, seven items.
@roganjosh the site hosts cards similar to MTG and selections based on it. For some reason, the original dev thought it was a grand idea to load all the cards at once :D
Greasemonkey can't easily access local files and I didn't have any web hosting at the time so embedding a great honking chunk of json straight in the script was the best I could do
but if being IT for my family/extended family has taught me anything, the moment you show any level of competence they will come hunt you down later in life.
Yeah, Rogan, I feel like this was built from someone who was learning webdev and had SO, W3 open on the side. So like I said I will just give them an idea and run away. hopefully
if you don't hear from me on Monday, send help, they caught me :D (joking)
Heck, even the crappy fansite I made when I was 16 had a little window that pops up with the card data, but it didn't embed every existing card in the request.
So it's not a site that you want anything to do with in terms of code? If that's the case, my snippet I was thinking of would be useless
The closest I have as a self-contained example is this, with everything in a single script, but if they're working the way they are, I doubt theres anything useful they could extrapolate
The advice you give them might not even need to have code... Just "you should think carefully about whether you really need a feature that requires a full megabyte of data per page load"
You can just as easily use the setup to use wildcard filters on an SQL db to narrow a list of search results as you keep trying characters, but I don't have anything set up as a standalone example I could share
My secret shame is that I'm no good at geography. I can identify countries with very distinct outlines, like Italy, but any country whose contour is best described as "a round squiggle" is indistinguishable from all the others to me
Doing the "Place the labels" quiz at online.seterra.com/en/vgp/3007, I can definitely identify Ireland, the UK, Russia, Germany, France, Italy, Greece, Spain, and Portugal.
I know Norway is near the top but I can never remember if it's on the left or the right
I think part of the issue with Brexit is how the "hard" border will be represented. We demand a country border that's 3 pixels wider than all others on a map.
I'll give myself 9.5/46 because I know Iceland is a European island but if someone said "hey, what's the name of this island?" without revealing its location on the globe, I would never guess it
I once tried to understand all this stuff, with geodesics etc, and subsequently mentally dumped everything I'd read in the bin. It just isn't something I can properly visualise in my head, despite a globe being obvious
I think I understand the principle of Mercator: Wrap a cylinder around the globe and project from one to another by drawing lines through the globe's center. Wikipedia tells me there's a lot more math involved if you want it to work accurately on non-spherical planets, like Earth for example.
Last time I was looking at these was when I was figuring out texture mapping onto a sphere with mayavi/vtk. I was a bit surprised when I took a better look at the spherical result. I rarely look at globes.
There was a campaign to change the maps in schools in the UK. Completely pointless in most ways because nobody really cares anymore, but at the same time, the distortions in the Northern Hemisphere are severe
(I'm not going to argue that we can't be quaint at all on account of all the bad things that happen all the time, because bad things happened in the past too and those are quaint anyway)
@AndrasDeak in the confines of this room, I agree. Outside, people really don't. The one thing that's ever more obvious to me is how little anyone cares about facts
I'm currently in my local pub. At a guess, I know about 300 by name. I'm still sat chatting in this room. I'll tell you what I overheard earlier.
Sister booking an appointment for her brother that I think has learning difficulties of some kind. He needed an endoscopy. She couldn't read the letter. Her friend suggested "gynecology". So she dutifully rang the hospital saying "my brother needs to book in for a gynecology".
I considered raising the issue of how kids round here shouldn't be looking at the Mercator Projection in their classroom
I fixed it for them. I've made some disparaging remarks but if the Brexit mess (that I joke about) seems curious to outsiders, these are the people that feel most strongly about it and I'm not sure they could possibly have made an informed decision. There's bigger problems than map projections going on over here.
@roganjosh That said, I don't really think what they're doing/how they're doing it is a great idea. But I like the stylistics of my original passport, so..